Im trying to link with a game library that has already been compiled using mingw, called Raylib. However; whenever I use MSYS's gcc 10.2 it gives me the following undefined reference error:
gcc main.c -Iraylib-3.7.0_win64_mingw-w64/include -Lraylib-3.7.0_win64_mingw-w64/lib -lraylib -lopengl32 -lgdi32 -lwinmm
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: raylib-3.7.0_win64_mingw-w64/lib/libraylib.a(core.o):core.c:(.text+0x1f6e): undefined reference to '_assert'
It seems that I maybe missing a library? This is just one of many similar errors. The majority of these undefined references are for assert like the one listed above. Some deal with GLFW and other libraries. Has anyone experienced something like this on MSYS?
Looks like I needed to be directly in MSYS2 mingw64 environment (cmd prompt). I was using the regular MSYS2 MSYS environment.
Related
I have trouble making Clang work with MinGW on Windows.
I have MinGW-W64-builds-4.3.3 installed (GCC 7.2.0) as well as the newest Clang/LLVM (by installer on the website).
I am compiling with:
-target x86_64-pc-windows-gnu
option and Clang finds all the headers. Unfortunately there is an error from the linker when I am using OpenMP. It looks like this:
: undefined reference to `__imp___kmpc_fork_call'
\libgomp.a(team.o):(.text+0x19): undefined reference to `pthread_mutex_destroy'
...
When I try to use -fopenmp=libomp flag I am getting errors like this:
...: undefined reference to `__imp___kmpc_fork_call'
...: undefined reference to `__imp___kmpc_for_static_init_4'
...: undefined reference to `__imp___kmpc_for_static_fini'
...: undefined reference to `__imp___kmpc_barrier'
...
It all works without problems when compiling with GCC.
Is there a way to make it (openmp) work without Visual Studio installed? If no, is there some minimilastic Visual Studio installer which just pulls needed libraries/headers and not the whole IDE etc.?
I surely don't know what I am doing here. Explain like I am five answers are very appreciated.
What solved the issue for me was adding libomp.lib to the list of files to compile. This seems to be necessary no matter if I have -static in compiler options and no matter if it's:
-fopenmp=libomp
or
-fopenmp=libiomp5
(as the commenter suggested)
Summing things up, I needed:
clang --target x86_64-pc-windows-gnu -fopenmp=libomp ... C:\FULL\PATH\TO\libomp.lib
To make it work with MinGW-W64-builds-4.3.3 and Clang 5.0.1
I am trying to build a tool called sscep (http://www.klake.org/~jt/sscep/) for Windows. It does not run natively and I have a "patch" that changes sscep to make it compile on Windows.
After applying the patch, it does compile perfectly but the linker screws. I am using gcc in minGW/msys
The original messsage was that it couldn't find the crypto lib so I added the library with "-L../openssl-mingw/lib" which then didn't create any more errors. I also have the command line switch -lcrypto in my command: gcc -L../openssl-mingw/lib -lcrypto sscep.o init.o net.o sceputils.o pkcs7.o ias.o fileutils.o -o sscep.In this directory is a libcrypto.a. OpenSSL itself was compiled with the exact same compiler just running ./config && make && make test && make install. Also the sources were extracted using the minGW tar and not 7-zip.
After following all documentation this is my (truncated) output:
sscep.o:sscep.c:(.text+0x83): undefined reference to `WSAStartup#8'
sscep.o:sscep.c:(.text+0xa5): undefined reference to `WSACleanup#0'
sscep.o:sscep.c:(.text+0x3d5): undefined reference to `BIO_new_mem_buf'
sscep.o:sscep.c:(.text+0x3e0): undefined reference to `ASN1_INTEGER_new'
sscep.o:sscep.c:(.text+0x414): undefined reference to `a2i_ASN1_INTEGER'
sscep.o:sscep.c:(.text+0x432): undefined reference to `ASN1_INTEGER_to_BN'
sscep.o:sscep.c:(.text+0x448): undefined reference to `BN_bn2dec'
sscep.o:sscep.c:(.text+0xb7e): undefined reference to `EVP_des_cbc'
sscep.o:sscep.c:(.text+0xbaf): undefined reference to `EVP_bf_cbc'
sscep.o:sscep.c:(.text+0xbda): undefined reference to `EVP_des_cbc'
sscep.o:sscep.c:(.text+0xc02): undefined reference to `EVP_des_ede3_cbc'
sscep.o:sscep.c:(.text+0xc48): undefined reference to `EVP_md5'
sscep.o:sscep.c:(.text+0xc79): undefined reference to `EVP_md5'
sscep.o:sscep.c:(.text+0xca1): undefined reference to `EVP_sha1'
This goes on for every file in there and supposedly every function called.
Searching here and google resulted in a missing library but omitting the -L directive from above I get another error about not finding libcrypto. So I assume that the library is actually found but somewhat with wrong addresses or something?
Here my compiler/linker knowledge actually ends.
If it is possible that the patch is responsible for that (which I do not believe since these are all openssl functions and the compiling works) then I can provide you with it.
Edit: Is there any information that I should provide so someone can help me? The version of openssl is 1.0.1 if this makes any difference.
On this topic: If it does make a difference, could this error occur because of a wrong version. As far as I understand linker theory, this error should not originate from a wrong version unless all of the below functions were replaced by differently named ones (but then the compiler would have complained, I guess?).
Another addition: Since I am on a 64 bit Windows 7, I tried to compile it with -m32 flag but that did not help. I assume since mingw is already 32 bit only, I can't even build x64. Another question is whether it is a problem that I am running in a virtualized environment on an AMD Opteron while openssl is built with the command "-march=i486"?
With some help I could finally figure this out! It was a problem of the order AND a problem of missing libraries. The combination killed me.
The libraries had to be -lcrypto -lws2_32 -lgdi32 not just -lcrypto. Furthermore, I had to append the libraries after the object files, so: $(CC) $(CFLAGS) $(OBJS) -lcrypto -lws2_32 -lgdi32 -o $(PROG) was the right make line.
Finally with this, it compiles fine. I didn't even need any architecture flags and such.
I am trying to use the functions from boost::filesystem to change my current working directory (and create it if necessary). I am getting linking errors:
SBDir.cpp:(.text+0x23): undefined reference to `boost::system::generic_category()'
SBDir.cpp:(.text+0x2f): undefined reference to `boost::system::generic_category()'
SBDir.cpp:(.text+0x3b): undefined reference to `boost::system::system_category()'
But I am linking against the boost libraries??!? I use the following:
-lboost_system -lboost_system-mt -lboost_filesystem -lboost_filesystem-mt
And I know it can find them because with -Wl, -t I get:
-lboost_system (/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/libboost_system.so)
-lboost_system-mt (/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/libboost_system-mt.so)
-lboost_filesystem (/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/libboost_filesystem.so)
-lboost_filesystem-mt (/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/libboost_filesystem-mt.so)
FWIW: I'm using gcc Ubuntu 4.4.3-4ubuntu54.4.3.
I had this same error message with boost 1.46 (standard with Ubuntu 11.10) and I had to add -lboost_system which I didn't need in 11.04 and boost 1.42. It doesn't answer your question but possibly of interest to others brought here by googling the error message.
So I couldn't figure out what went wrong -- so I tried un-installing the Ubuntu boost package and building it from scratch. I upgraded to 1.45.0 & now everything links. Not sure whether this was a version specific problem or not, but if I learn more later I'll come back and update.
I'm doing a opengl program, and found an example that does what I want, but when I try to compile it, using
gcc -o picksquare picksquare.c -lglut
I get:
/tmp/cchE9Z0Y.o: In function `pickSquares':
picksquare.c:(.text+0x41d): undefined reference to `gluPickMatrix'
picksquare.c:(.text+0x442): undefined reference to `gluOrtho2D'
/tmp/cchE9Z0Y.o: In function `reshape':
picksquare.c:(.text+0x508): undefined reference to `gluOrtho2D'
collect2: ld returned 1 exit status
And the code example is here:
http://www.opengl.org/resources/code/samples/redbook/picksquare.c
Thanx for your answer guys, but invoking with -lglu says it can't find glu, and invoking with -lGL gives the same undefined reference. What is this glu? Does anyone know?
Try this:
gcc filename_here -lglut -lGLU
This should work fine. The last word in the above sentence is lGLU (not one but l for lion) .
Because you're calling functions in the GLU library (which is not the same as GLUT), without linking to it.
Add -lglu to your command line.
Note that the functions failing have glu as their prefix, not glut.
If adding -lglu gives you a new error, that might mean you development system doesn't have the GLU library installed. It's an optionalal library independent of OpenGL, so just because you have installed development support for OpenGL there's no guarantee that you also have it for GLU.
Looks like you don't have the necessary libraries installed or you need to point your LD_LIBRARY_PATH to a correct location to pick up libglut.so.
AFAIK, for gluOrtho2D & co. you have to link against libGL, which means you have to add a -lGL switch on your command line.
Ok, found the problem, I wasn't adding the glu library to the gcc compiler, addind '-lGLU' solved the problem. Thanx anyways guys!!
Is there a site where I can find the symbols used in a particular library and its version.
For e.g. I m trying to compile some code on AIX using gcc, and it throws me a lot of undefined symbol errors
For example, here is an output:
ld: 0711-317 ERROR: Undefined symbol: .__fixdfdi
ld: 0711-317 ERROR: Undefined symbol: .__divdi3
ld: 0711-317 ERROR: Undefined symbol: .__moddi3
ld: 0711-317 ERROR: Undefined symbol: .__floatdidf
ld: 0711-317 ERROR: Undefined symbol: .__umoddi3
ld: 0711-317 ERROR: Undefined symbol: .__udivdi3
ld: 0711-317 ERROR: Undefined symbol: .__fixunsdfdi
Where do I go to find where these symbols are.
If I run the same gcc command on Linux, it runs fine.
I tried including -lgcc also but then again it throws undefined symbols for some register_frame ...blah blah...
and I m getting sick of AIX.
Any help on this would be appreciated..and please don't bother Googling on this issue.
You will end up no where.
Many have asked this kind of questions but no answers.
Thanks
It's been a long time since I compiled anything on AIX (thankfully) and I do feel your pain having spent a good year or so trying to get our company's JNI and other software libraries built on AIX.
I do seem to remember that GCC never worked particularly well as it always came up with similar errors. Is there any option to use the native compiler (xlC)?
Failing that I would check the ordering of your libraries, it plays a big part in making stuff work properly..
I take it that you have use the nm utility to iterate through every library in /usr/lib (etc) to find where the missing symbols are located?
Those are math symbols. Try adding -lm to your link line.
This is because you used the gcc to compile a library you want to link to a code compiled with xlc. Or at least is my case
You have 2 options:
use the xlc instead of gcc for all the compilation (don't mix gcc and xlc)
compile with xlc but calling also the gcc libraries, for instance:
sudo find / -name libgcc.a
/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/libgcc.a
/opt/IBM/xlC/13.1.0/bin/xlC -g -o MyBIN MyBIN.o -L/usr/etctera -
L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/ -lgcc -letcetera
Mostly questions:
Which version of GCC?
Which version of AIX are you on?
Which version of AIX was your copy of GCC built for?
What exactly is the link line you are using?
I've seen that sort of error when using a version of GCC compiled on a down-version of AIX. For example, if the GCC was compiled for AIX 4.3.3 and is being run on AIX 5.x. Usually, if GCC was compiled on an up-version of AIX, it won't run on the down-version, so that is unlikely to be the problem.
One other (rather unlikely) possibility: is your GCC installed where it was compiled to expect to be installed? When you build it, you specify (possibly implicitly) the install location (by default, under /usr/local). If you have your copy installed somewhere else, but there's an old GCC in /usr/local and your copy expects to be installed in /usr/local, then you can run into this sort of problem. This is much less likely than version mismatching.
Listed external symbols are from libgcc so add of -lgcc is correct. And register_frame also is part of libgcc but only for 32-bit. Check if you use the same bit depth mode for you compiler, linker and libraries.