This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
while I am working on rendering fonts using ftgl in my opengl project I am encountering errors stating
g++ -o mygame Sample_GL3_2D.cpp glad.c -lGL -lglfw -ldl -lftgl -lSOIL -I /usr/include/freetype2 -L/usr/local/lib -lfreetype
/usr/local/lib/libftgl.so: undefined reference to `__glewGenBuffers'
/usr/local/lib/libftgl.so: undefined reference to `glewInit'
/usr/local/lib/libftgl.so: undefined reference to `__glewBindVertexArray'
/usr/local/lib/libftgl.so: undefined reference to `__glewBindBuffer'
/usr/local/lib/libftgl.so: undefined reference to `__glewUniform3f'
/usr/local/lib/libftgl.so: undefined reference to `__glewVertexAttribPointer'
/usr/local/lib/libftgl.so: undefined reference to `__glewBufferData'
/usr/local/lib/libftgl.so: undefined reference to `__glewDeleteBuffers'
/usr/local/lib/libftgl.so: undefined reference to `__glewDeleteVertexArrays'
/usr/local/lib/libftgl.so: undefined reference to `__glewGenVertexArrays'
/usr/local/lib/libftgl.so: undefined reference to `__glewEnableVertexAttribArray'
these are my contents in Makefile
all:mygame
mygame: Sample_GL3_2D.cpp glad.c
g++ -o mygame Sample_GL3_2D.cpp glad.c -lGL -lglfw -ldl -lftgl -lSOIL -I /usr/include/freetype2 -L/usr/local/lib -lfreetype
clean:
rm mygame
looks like the errors is being raised by the libftgl.so library. I have installed the GLEW using the glew packages in the ubuntu. but dont understand why it isn't being referenced.
You aren't referencing the GLEW library on the compile/link line. The -l flag to g++ is tells it to tell the linker to the link the library e.g. -lftgl tells it to look for the ftgllibrary and link it.
You don't have -lGLEW (or -lglew if the library is named using lowercase) so it isn't linked. Also see this answer
error undefined reference to `FTExtrudeFont::FTExtrudeFont(char const*)'
Maybe the two of you should get together and try and help each other since you are appear to be trying to solve the same (homework?) problem.
Related
I have some RSA code, however, I can't get it to compile & link properly.
build.sh:
x86_64-w64-mingw32-g++ rsa.cpp -L/usr/local/opt/openssl/lib -lcrypto -lssl -I/usr/local/opt/openssl/include/ -static-libstdc++ -static-libgcc -o main.exe
result:
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0xe6): undefined reference to `BIO_new_mem_buf'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0xef): undefined reference to `BIO_f_base64'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0xf7): undefined reference to `BIO_new'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x10b): undefined reference to `BIO_push'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x130): undefined reference to `BIO_read'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x146): undefined reference to `BIO_free_all'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x177): undefined reference to `EVP_PKEY_new'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x193): undefined reference to `EVP_PKEY_assign'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x198): undefined reference to `EVP_MD_CTX_create'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x1a5): undefined reference to `EVP_sha256'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x1c7): undefined reference to `EVP_DigestVerifyInit'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x1f1): undefined reference to `EVP_DigestUpdate'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x218): undefined reference to `EVP_DigestVerifyFinal'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x234): undefined reference to `EVP_MD_CTX_cleanup'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x254): undefined reference to `EVP_MD_CTX_cleanup'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x26e): undefined reference to `EVP_MD_CTX_cleanup'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x2ac): undefined reference to `BIO_new_mem_buf'
/var/folders/8k/t6rljvrs6l32k49b3834_njr0000gn/T//ccKr56mH.o:rsa.cpp:(.text+0x2da): undefined reference to `PEM_read_bio_RSA_PUBKEY'
collect2: error: ld returned 1 exit status
both libcrypto.a and libssl.a exist in /usr/local/opt/openssl/lib. I'm building on OS X mingw compiler a windows application.
EDIT: objdump -d /usr/local/opt/openssl/lib/libcrypto.a > ~/libcrypto.a.txt
EDIT2: Tried grouping: x86_64-w64-mingw32-g++ rsa.cpp -L/usr/local/opt/openssl/lib -Wl,--start-group -lcrypto -lssl -Wl,--end-group -lws2_32 -lwsock32 -liphlpapi -I/usr/local/opt/openssl/include/ -static-libstdc++ -static-libgcc -o main.exe, same result
This question already has answers here:
g++ linking order dependency when linking c code to c++ code
(4 answers)
Closed 6 years ago.
I made a TCP socket program in C++ that uses wsock32 and openssl, but I want to link openssl static.
I have compiled openssl on mingw32 with shared and no-shared but I keep getting the same undefined reference errors.
It builds fine if I link the .a.dll instead of .a but I don't want to use dll's.
Here's how I compile:
/c/MinGW/bin/mingw32-g++.exe main.cpp -I /c/Mingw-builds/openssl/include -L/c/MinGW/lib -L /c/Mingw-builds/openssl/lib -std=c++11 -lwsock32 -lshlwapi -lws2_32 -lssl -lcrypto -lgdi32
Errors that I get:
C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xac): undefined reference to `getnameinfo#28'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0x6ef): undefined reference to `freeaddrinfo#4'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xa28): undefined reference to `getaddrinfo#16'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0xe6): undefined reference to `WSAGetLastError#0'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x2d6): undefined reference to `WSAGetLastError#0'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x40b): undefined reference to `getsockopt#20'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x43b): undefined reference to `gethostbyname#4'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x4a0): undefined reference to `WSAGetLastError#0'
Nvm got it working by ordering it right:
/c/MinGW/bin/mingw32-g++.exe main.cpp -o asdf.o -I /c/Mingw-builds/openssl/include -L /c/Mingw-builds/openssl/lib -std=c++11 -lmingw32 -lssl -lcrypto -luser32 -lgdi32 -lws2_32 -lwsock32 -lshlwapi -static-libgcc -static-libstdc++ -shared
I have compiled libcurl using mingw32 and am trying to link it with my program using mingw32 for a Windows system from my Linux machine.
I was outputted the files, libcurl-4.dll libcurl.a libcurl.la libcurl.lai.
I have included them in my mingw32 libs folder at: /usr/x86_64-w64-mingw32/lib
I was able to find a few other topics on linking with the libstdc++ and libgcc to take care dependency errors while executed but when trying to add libcurl.a it will not compile period.
I used the following:
$ x86_64-w64-mingw32-g++ main.cpp -o hello.exe -static-libgcc -static-libstdc++ -static "/usr/x86_64-w64-mingw32/lib/libcurl.a" -lpthread
However, I cannot not get it to use the libcurl.a and am continuing to receive these errors.
/tmp/ccIceRus.o:main.cpp:(.text+0xde): undefined reference to `__imp_curl_easy_init'
/tmp/ccIceRus.o:main.cpp:(.text+0x106): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x122): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x13e): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x159): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x169): undefined reference to `__imp_curl_easy_perform'
/tmp/ccIceRus.o:main.cpp:(.text+0x180): undefined reference to `__imp_curl_easy_strerror'
/tmp/ccIceRus.o:main.cpp:(.text+0x197): undefined reference to `__imp_curl_easy_cleanup'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccIceRus.o: bad reloc address 0x80 in section `.xdata'
collect2: error: ld returned 1 exit status
What am I doing wrong?. I can not get past this. I know it has to be some stupid issue.
Thank you.
I was able to solve the question by specifying -DCURL_STATICLIB, as well as linking some other dependencies.
x86_64-w64-mingw32-g++ main.cpp -o hello.exe -DCURL_STATICLIB -static -lstdc++ -lgcc -lpthread -lcurl -lwldap32 -lws2_32
I am compiling a program with the following flags and getting errors (running 64 bit os):
g++ -lm -lml -lcvaux -lhighgui -lcv -lcxcore main.o BRIEF.o -o BRIEF_demo
I get a bunch of undefined references:
main.cpp:(.text+0x1f6): undefined reference to `cvInitMatHeader'
main.cpp:(.text+0x218): undefined reference to cvInitMatHeader'
main.o: In function_Z14drawQuadrangleP9_IplImageiiiiiiii8CvScalari.constprop.77':
main.cpp:(.text+0x2d5): undefined reference to cvLine'
main.cpp:(.text+0x333): undefined reference tocvLine'
main.cpp:(.text+0x398): undefined reference to cvLine'
main.cpp:(.text+0x3f2): undefined reference tocvLine'
Anyone have an idea how to circumvent this?
I suppose you are using the newest OpenCV 2.3.x. cvInitMatHeader() and cvLine() are actually defined in libcxcore.so, which I can see you are including.
My guess is that the order of the linking is wrong, so you need to adjust your command to something like:
g++ main.cpp BRIEF.cpp -o BRIEF_demo -lm -lml -lcvaux -lhighgui -lcv -lcxcore
I am in linux. My Makefile file is this
main2: main.cpp
g++ -c $(LIBS) $(CFLAGS) -fPIC main.cpp
g++ -shared main.o -o main.so
Where,
SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LDFLAGS := $(shell sdl-config --libs)
CC = gcc
COPTS = -g -Wall
CFLAGS = $(SDL_CFLAGS)
LIBS = -lstdc++ -lSDL $(SDL_LDFLAGS) -L/usr/X11R6/lib -lGL -lGLU
which runs
g++ -c -lstdc++ -lSDL -L/usr/lib -lSDL -L/usr/X11R6/lib -lGL -lGLU -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -fPIC main.cpp
g++ -shared main.o -o main.so
Now, this works without error. main.o and main.so files are produced.
However, when I try to link main.os with python ctypes
from ctypes import * import os
libtest = cdll.LoadLibrary(os.getcwd()+ '/main.so') libtest.main_loop()
libtest.main_loop()
I get this error
>>> libtest = cdll.LoadLibrary(os.getcwd() + '/main.so')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/atomos/DF/open_gl_client/ctypes_client/main.so: undefined symbol: glEnd
I am not sure if I am creating the linked library correctly. How do I create a linked library that I can load?
Do I have to create a .o and .os file for every library I import from main.cpp or is that taken care of automatically?
I do not understand what the compiler or linker is doing, however it works for a simple example with no imports, but for cpp files which import opengl libraries, it gives that error.
---- Update----
ldd against main.so yields
ldd main.so
linux-gate.so.1 => (0xb7755000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xaf625000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xaf5ff000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xaf4a4000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xaf485000)
/lib/ld-linux.so.2 (0xb7756000)
---- Update ----
I ran g++ without -shared flag in the second compilation step and received this error
g++ main.o -o main.so
main.o: In function `Texture_map_list::add_texture(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
main.cpp:(.text+0xf0fe): undefined reference to `glGenTextures'
main.cpp:(.text+0xf2ba): undefined reference to `glBindTexture'
main.cpp:(.text+0xf2d7): undefined reference to `glTexParameterf'
main.cpp:(.text+0xf2f4): undefined reference to `glTexParameterf'
main.cpp:(.text+0xf310): undefined reference to `glTexParameteri'
main.cpp:(.text+0xf32c): undefined reference to `glTexParameteri'
main.cpp:(.text+0xf365): undefined reference to `gluBuild2DMipmaps'
main.o: In function `init()':
main.cpp:(.text+0xf457): undefined reference to `SDL_Init'
main.cpp:(.text+0xf46d): undefined reference to `SDL_WM_SetCaption'
main.cpp:(.text+0xf472): undefined reference to `SDL_GetVideoInfo'
main.cpp:(.text+0xf480): undefined reference to `SDL_GetError'
main.cpp:(.text+0xf497): undefined reference to `SDL_Quit'
main.cpp:(.text+0xf4e2): undefined reference to `SDL_GL_SetAttribute'
main.cpp:(.text+0xf505): undefined reference to `SDL_SetVideoMode'
main.cpp:(.text+0xf513): undefined reference to `SDL_GetError'
main.cpp:(.text+0xf52a): undefined reference to `SDL_Quit'
main.cpp:(.text+0xf559): undefined reference to `glClearColor'
main.cpp:(.text+0xf565): undefined reference to `glEnable'
main.cpp:(.text+0xf571): undefined reference to `glMatrixMode'
main.cpp:(.text+0xf576): undefined reference to `glLoadIdentity'
main.cpp:(.text+0xf5a2): undefined reference to `gluPerspective'
main.o: In function `process_keypresses()':
main.cpp:(.text+0x10678): undefined reference to `SDL_PollEvent'
main.cpp:(.text+0x109a1): undefined reference to `SDL_PollEvent'
main.o: In function `main_loop':
main.cpp:(.text+0x10d76): undefined reference to `SDL_GetKeyState'
main.cpp:(.text+0x10d9f): undefined reference to `SDL_Quit'
main.o: In function `render()':
main.cpp:(.text+0x10e00): undefined reference to `SDL_GetMouseState'
main.cpp:(.text+0x10e90): undefined reference to `SDL_GetMouseState'
main.cpp:(.text+0x10f94): undefined reference to `glClear'
main.cpp:(.text+0x10fa0): undefined reference to `glMatrixMode'
main.cpp:(.text+0x10fa5): undefined reference to `glLoadIdentity'
main.cpp:(.text+0x11081): undefined reference to `gluLookAt'
main.cpp:(.text+0x11120): undefined reference to `glTranslatef'
main.cpp:(.text+0x1114d): undefined reference to `glRotatef'
main.cpp:(.text+0x1117a): undefined reference to `glRotatef'
main.cpp:(.text+0x1119e): undefined reference to `SDL_GL_SwapBuffers'
main.o: In function `draw_plane(float, float, float)':
main.cpp:(.text+0x111d8): undefined reference to `glColor3f'
main.cpp:(.text+0x111e4): undefined reference to `glBegin'
main.cpp:(.text+0x1120b): undefined reference to `glVertex3f'
....
First, note that this is easier to debug if you don't build a shared library. You are building with -shared so the linker errors don't happen until you dynamically load the library in Python. Turn off -shared while you are debugging, and you will see the errors on the command-line when you try to link:
g++ main.o -o main
main.o: In function `main':
main.cpp:(.text+0x1d): undefined reference to `glBegin'
main.cpp:(.text+0x22): undefined reference to `glEnd'
collect2: ld returned 1 exit status
Now the problem is that you are passing linker arguments to the compiler. I see that you have nicely separated CFLAGS and LIBS in the Makefile. Good. But you are passing both $(LIBS) and $(CFLAGS) on the first line, to build main.o. The LIBS will be ignored on that line, because they are link flags.
On the second line, where you are actually building the final executable, you do not pass $(LIBS), so the program is not linked with libGL or any other libraries.
Therefore, simply fix your makefile thusly:
main2: main.cpp
g++ -c $(CFLAGS) -fPIC main.cpp
g++ -shared main.o $(LIBS) -o main.so
Edit: I have since realised that in GCC, you must always put the libraries after the object files, so I have changed the last line of the makefile accordingly.
Simple:
You are passing the link flags to object compilation step.
Here is what you need:
g++ -c -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT main.cpp
g++ -lstdc++ -lSDL -L/usr/lib -lSDL -L/usr/X11R6/lib -lGL -lGLU -fPIC main.o -o main
Plus you probably don't want to create so file, but a normal executable.