Cannot find sdl2main

人走茶凉 提交于 2020-01-06 07:05:06

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/22739563/cannot-find-sdl2main

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!