Cannot find sdl2main

2019-09-10 04:14发布

I'm trying to compile code using SDL, I can't really post much of the code here but I can do my best to answer questions about it. The problem occurs when compiling the view code and trying to link the SDL libraries.

g++ -o test test.c -lSDL2main -lSDL2

gives me an error /usr/bin/ld: cannot find -lSDL2main

I know my SDL install is okay because if I leave out the link to SDL2main it compiles fine and runs fine. The problem is there is other code that needs SDL2main. I've poured through my file system and I can't find it and I've searched online pretty exhaustively. I was just hoping someone could help me either resolve the dependency or fix my sdl install if its broken.

标签: c++ graphics g++
1条回答
成全新的幸福
2楼-- · 2019-09-10 04:44

If you are using some distro there's probably some tool to search files, even in packages not installed.

For example (I'm using Debian/unstable) apt-file search SDL2main

libsdl2-dev: /usr/lib/i386-linux-gnu/libSDL2main.a

libsdl2-2.0-0:i386       2.0.2+dfsg1-4            
libsdl2-dev              2.0.2+dfsg1-4             

Once you've verified that the lib exist if it doesn't link there still something to check and try

Check the lib is installed in one of the search path (see How to print the ld(linker) search path)

Or explicit the path

g++ -o test test.c -L/usr/lib/i386-linux-gnu -lSDL2main -lSDL2

Being a static library with some gcc/g++/ld version maybe you need to link the archive as an object, without -l

g++ -o test test.c /usr/lib/i386-linux-gnu/libSDL2main.a -lSDL2

查看更多
登录 后发表回答