编译错误/ usr / bin / ld:找不到-lSDL collect2

当我做

$ gcc cube.c -lglut -lGL -lGLU -lSDL /usr/bin/ld: cannot find -lSDL collect2: error: ld returned 1 exit status 

当我做

 $ sudo apt-get install libsdl* Reading package lists... Building dependency tree... Reading state information... libsdl-image1.2 is already the newest version. libsdl-image1.2 set to manually installed. libsdl1.2debian is already the newest version. libsdl1.2debian set to manually installed. Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: libsdformat-dev : Depends: libboost-regex-dev but it is not going to be installed Depends: liburdfdom-dev but it is not going to be installed libsdl-image1.2-dev : Depends: libtiff-dev libsdl-mixer1.2-dev : Depends: libflac-dev (>= 1.2.1) but it is not going to be installed Depends: libvorbis-dev (>= 1.2.0) but it is not going to be installed libsdl1.2-dbg : Depends: libsdl1.2debian (= 1.2.15-8ubuntu1) but 1.2.15-8ubuntu1.1 is to be installed libsdl1.2-dev : Depends: libsdl1.2debian (= 1.2.15-8ubuntu1) but 1.2.15-8ubuntu1.1 is to be installed Depends: libpulse-dev but it is not going to be installed libsdl2-dev : Depends: libpulse-dev but it is not going to be installed Depends: libudev-dev but it is not going to be installed 

似乎libsdl安装没有成功。 在搜索libsdl时,有两个版本libsdl1和libsdl2。 我正在考虑找到一些其他方法来安装它们。 有人对安装有任何建议吗?

@steeldriver:我做了你的建议,输出结果如下:

 $ sudo apt-get update && sudo apt-get upgrade finished... $ sudo apt-get install libsdl1.2-dev Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: libsdl1.2-dev : Depends: libsdl1.2debian (= 1.2.15-8ubuntu1) but 1.2.15-8ubuntu1.1 is to be installed Depends: libpulse-dev but it is not going to be installed E: Unable to correct problems, you have held broken packages. 

AB根据您的要求。 这是评论中的命令输出。

我什么时候做的

 $ apt-cache policy libsdl1.2-dev libsdl1.2-dev: Installed: (none) Candidate: 1.2.15-8ubuntu1 Version table: 1.2.15-8ubuntu1 0 500 http://ubuntu.mirror.crucial.com.au/ trusty/main amd64 Packages 

我什么时候做的

 $ apt-cache policy libsdl1.2debian libsdl1.2debian: Installed: 1.2.15-8ubuntu1.1 Candidate: 1.2.15-8ubuntu1.1 Version table: *** 1.2.15-8ubuntu1.1 0 100 /var/lib/dpkg/status 1.2.15-8ubuntu1 0 500 http://ubuntu.mirror.crucial.com.au/ trusty/main amd64 Packages 

我什么时候做的

 $ apt-cache policy libpulse-dev libpulse-dev: Installed: (none) Candidate: 1:4.0-0ubuntu11 Version table: 1:4.0-0ubuntu11 0 500 http://ubuntu.mirror.crucial.com.au/ trusty/main amd64 Packages 

AB:当我做的时候。 降级发生了。

 $ sudo apt-get install libsdl1.2debian=1.2.15-8ubuntu1 Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be DOWNGRADED: libsdl1.2debian 0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded. Need to get 162 kB of archives. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] y WARNING: The following packages cannot be authenticated! libsdl1.2debian Install these packages without verification? [y/N] y Get:1 http://ubuntu.mirror.crucial.com.au/ trusty/main libsdl1.2debian amd64 1.2.15-8ubuntu1 [162 kB] Fetched 162 kB in 0s (243 kB/s) dpkg: warning: downgrading libsdl1.2debian:amd64 from 1.2.15-8ubuntu1.1 to 1.2.15-8ubuntu1 (Reading database ... 443054 files and directories currently installed.) Preparing to unpack .../libsdl1.2debian_1.2.15-8ubuntu1_amd64.deb ... Unpacking libsdl1.2debian:amd64 (1.2.15-8ubuntu1) over (1.2.15-8ubuntu1.1) ... Setting up libsdl1.2debian:amd64 (1.2.15-8ubuntu1) ... Processing triggers for libc-bin (2.19-0ubuntu6.6) ... 

由道格的建议解决

 Open up Software & Updates > Updates tab & make sure that the first 2 are enabled. (- trusty-security, trusty-updates). If one or the other wasn't enabled then do so, after that reload sources & proceed. 

谢谢你的解决方案,道格! 感谢所有参与此问题的人特别是钢铁驱动器和AB!

打开“软件和更新”>“更新”选项卡,确保启用前2个。 ( – 可信赖安全,可信赖更新)。 如果未启用其中一个,则在重新加载源并继续之后执行此操作。

如果两者都在那里尝试切换主页上的服务器>从下载:使用主服务器。 然后重新加载资源并查看。

您需要libsdl1.2-dev(1.2.15-8ubuntu1.1)才能使用它应该是,于04/14发布 – http://packages.ubuntu.com/trusty-updates/libsdl1.2-dev

尝试像gcc cube.c $(pkg-config --libs glut gl glu sdl) 。 虽然不完全确定这些包名。