User forums > Using Code::Blocks

Linking problem with CLANG & Code::Blocks, linking works with GCC & Code::Blocks

(1/3) > >>

jalcazo:
Hi, I'm developing this project with Code::Blocks. (check out a gameplay video or this other discussion about it if you want more information. Or the project's Facebook page).



I started programming it with pure modular C, Tilengine for sprites & pixel art etc, SDL2 for mouse control, SDL2_mixer for audio (mp3 music and sound FX), SDL2_ttf for drawing text (including some Japanese characters), and SDL2 image (I don't remember why this one, but I used it somehow or somewhere).

So my general linker options look like this with GCC:

--- Code: ----lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer -lSDL2_ttf -lSDL2_image

--- End code ---

And a link to Tilengine.lib library:



Please notice this is for the topmost project options "Morgana". Below i have two target builds, one for GCC and one for CLANG. This one is for GCC:



and the linking options vary a little from "Morgana" general linker options:


--- Code: ----lws2_32 -lSDL2main -lSDL2 -lSDL2_mixer -lSDL2_ttf -lSDL2_image

--- End code ---

I rebooted the development of the project at some point and I'm migrating it to C++ OOP with Code::Blocks and GCC (and the same libraries mentioned). I plan to open source the project some day, and to do a Kickstarter for it, when I have a *MUCH* mature version and could dedicate all the time that this project needs (I have two little daughters).

Meanwhile I have a question. I use Code::Blocks and GCC for compiling without problems, but I want to use CLANG for its static analyzer and to check for more errors, but I have a linking problem. Besides I have no clue on how to trigger the CLANG analyzer. I used CppCheck integrated with Code::Blocks with no problems. I even change the Mingw used for one that uses posix threads for some thread I needed somewhere.

Well, my CLANG linking options are blank, so it uses the ones from "Morgana":



The compilation with GCC is successful:



But it fails with CLANG, since it cannot find m.lib



(cannot find m.lib in spanish)

--- Code: ---LINK : fatal error LNK1181: no se puede abrir el archivo de entrada 'm.lib'
--- End code ---

But if I remove -lm option then it doesn't compile with GCC. I also used the option "Use target options only" for CLANG build and blank linker options with Tilengine.lib linking at the side.

But then it says there is no entry point (no main). I don't know how to link SDL2 and the other libraries to CLANG. I think I installed them on top of LLVM CLANG directories as I did with MingW, but it doesn't work.


--- Code: ---LINK : fatal error LNK1561: se debe definir el punto de entrada
--- End code ---

Then I tried to add this options to CLANG linker:


--- Code: ----lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer -lSDL2_ttf -lSDL2_image
--- End code ---

But then it says that cannot find SDL2main.lib linking error.  ???

I don't understand why, where is that file? When you download SDL2 comes with no .lib files, just .a files and other stuff.

Sorry for the noobness  :-[ :-[ :-[.  I would like to fix the linking with CLANG as it worked with GCC, please can you help me or point me to some useful information?

jalcazo:
Update. Now I tried adding this libraries:


--- Code: ---C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\lib\libSDL2main.a C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\lib\libSDL2_mixer.a C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\lib\libSDL2_ttf.a C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\lib\libSDL2_image.a W:\Morgana\Tilengine.lib

--- End code ---



It detects the libraries, but now it says it has NO entry point ("se debe definir el punto de entrada" is "you must define an entry point" (main) in spanish):


--- Code: ---LINK : fatal error LNK1561: se debe definir el punto de entrada
clang++: error: linker command failed with exit code 1561 (use -v to see invocation)
Process terminated with status 1561 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

--- End code ---

BlueHazzard:
The best  would be to post full rebuild logs to see where the problem is:
(obligatory link to faq, but the wiki is down ;( ) https://web.archive.org/web/20200123060135/http://wiki.codeblocks.org/index.php/FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

About the main entry point not finding:
Make sure that your cpp file where the main is located is enabled to build for the clang target:
Project->Properties->Build targets->select the clang target on the left->Make sure build target files in the right bottom is set correctly.

jalcazo:
TEST: Hi, I'm trying to post an answer but it doesn't work.

jalcazo:
Update 2.

Ok, using some help I added:


--- Code: ----Xlinker /subsystem:windows
--- End code ---



And now says machine type of library 'x64' is in conflict with the machine type of the destination 'x86'.

Navigation

[0] Message Index

[#] Next page

Go to full version