Search code examples
windowsmakefilecodeblocksmingw32

cbp2make linking libraries with ".a" on windows


I am trying to generate a makefile from a codeblock project file ".cbp" with the cbp2make tool on windows. But the generated makefile has unix format archive libraries :

LIB = libkernerl32.a libuser32.a libgdi32.a

, which causes issues when trying to use mingw32-make.exe, it complains that libkernerl32.a is missing

When I compile through codeblock I see in the build log that it uses -lkernerl32 luser32 -lgdi32.

I looked at the project.cbp in a text editor and noticed that under there is : etc ...

So I assume codeblock changes those from libkernel32.a to -lkernel32 when building, which cbp2make does not seem to do when generating the makefile.

I run : cbp2make.exe -in project.cbp -out makefile -windows

How can I get cbp2make to have : LIB = -lkernel32 -luser32 Instead of LIB = libkernel32.a libuser32.a ?


Solution

  • cbp2make behaves somewhat differently to CodeBlocks when generating linking argument line.

    CodeBlocks will automatically add -l (link_library_switch), remove lib (library_prefix) prefix and remove extension for static linking libraries listed with (at least) a extension (managed to test only that case). For dynamic linking libraries the extension of so it will not be removed.

    cb2make on the other hand is not so smart. It does not automatically remove the lib prefix nor the extension (at lest at rev 147). However what it does underneath (cbproject.cpp:790) is it checks whether a library is specified with an extension.

    If extension is present, it will simply copy-paste the library entry, preserving it's path (if given). If, on the other hand, the extension is not present, it will assume that the user did not give a full path to the lib, but instead wants the linker to search for it. It will prefix the library name with -l but it will not remove the lib prefix automatically (which at least for g++ does not matter).

    So to make sure both CodeBlocks and cbp2make are able to link in a similar manner I'd recommend:

    • Do not prefix the library name with lib i.e. use pthread instead of libpthread,
    • Do not suffix the library name with extension i.e. use pthread instead of pthread.so,
    • It does not matter if the extension is a known library extension type. If you have a library named libfoo.bar.baz.so you're screwed and have to correct the Makefile manually,
    • Optionally: Do not give the full (relative) path to the library.

    Also please note: link_library_switch and library_prefix are compiler/linker/platform dependant. Please consult cbp2make configuration file for more information (cbp2make.cfg).

    Generally speaking cbp2make is not handling this very well, despite having all the platform/compiler specific details in the configuration file and internal data structures.