Answer the question
In order to leave comments, you need to log in
Creating a dynamic library?
We need to create a dynamic library. Everything works in the development environment. When assembling by hand, I miss something (I guess what, but I didn’t google how to fix it).
Here are my steps:
g++ -std=c++11 -fPIC -c mygl.cpp
g++ -shared -o libmygl.so mygl.o
g++ -std=c++11 -fPIC -c main.cpp
g++ main.o -L. -lmygl -o result
main.o: In function `main':
main.cpp:(.text+0x1d): undefined reference to `SDL_Init'
main.cpp:(.text+0x4b): undefined reference to `SDL_GL_SetAttribute'
main.cpp:(.text+0x5a): undefined reference to `SDL_GL_SetAttribute'
main.cpp:(.text+0x69): undefined reference to `SDL_GL_SetAttribute'
main.cpp:(.text+0x78): undefined reference to `SDL_GL_SetAttribute'
main.cpp:(.text+0x87): undefined reference to `SDL_GL_SetAttribute'
main.o:main.cpp:(.text+0x96): more undefined references to `SDL_GL_SetAttribute' follow
main.o: In function `main':
main.cpp:(.text+0xdb): undefined reference to `SDL_CreateWindow'
main.cpp:(.text+0x127): undefined reference to `SDL_GL_CreateContext'
main.cpp:(.text+0x183): undefined reference to `SDL_PollEvent'
main.cpp:(.text+0x1bf): undefined reference to `SDL_GL_SwapWindow'
main.cpp:(.text+0x1cc): undefined reference to `SDL_GetModState'
main.cpp:(.text+0x1f7): undefined reference to `SDL_GL_DeleteContext'
main.cpp:(.text+0x203): undefined reference to `SDL_DestroyWindow'
main.cpp:(.text+0x20d): undefined reference to `SDL_Quit'
./libmygl.so: undefined reference to `SDL_GL_LoadLibrary'
./libmygl.so: undefined reference to `SDL_GL_GetProcAddress'
./libmygl.so: undefined reference to `SDL_GL_UnloadLibrary'
collect2: error: ld returned 1 exit status
Answer the question
In order to leave comments, you need to log in
Your program and dynamic library are not linked to the SDL library.
g++ -shared -o libmygl.so -std=c++11 -fPIC -c mygl.cpp -lsdl
g++ -o result -std=c++11 -L. -fPIC -c main.cpp -lsdl -lmygl
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question