使用g ++编译,无法更改库路径

时间:2013-09-25 14:10:15

标签: ubuntu g++

我似乎无法让这个工作。我有一个我自己没有写过的c ++脚本,我需要用g ++编译。脚本的开头如下所示:

#include "x.hh"
#include "y.hh"

#include <iostream>
...

我理解当使用带引号的include时,这意味着在进行编译时必须包含外部库。头文件,x.hh和y.hh,以及文件x.cc和y.cc(我猜是库)和主脚本都在同一个文件夹中。我试图用以下方法编译它们:

g ++ Documents / Cpp / script.cc -o script -L Documents / Cpp -lx -ly

这将返回错误:

/usr/bin/ld cannot find -lx
/usr/bin/ld cannot find -ly
collect2 returned 1 exit status

搜索路径与我指定的不同。即使我写了

g ++ Documents / Cpp / script.cc -o script -L sdfsdf / sdfsd-lx -ly

它仍然在/ usr / bin / ld文件夹中查找。无论我写什么-L我都无法让它发挥作用。怎么样?

1 个答案:

答案 0 :(得分:0)

编译所有.cc文件,它们都是构建程序所必需的。

g++ Documents/Cpp/*.cc sdfsdf/*.cc -o script

(假设sdfsdf是x.cc和y.cc的路径