GCC不编译程序

时间:2014-02-13 00:50:11

标签: gcc reference libraries

我想编译一个非常简单的C ++程序。在第一台机器上编译过程工作正常,程序运行正常。但是,在第二台linux机器上我发现了一些没有问题的库。编译过程如下所示:

gcc -o WebPageCrawler -lawesomium-1-7 -Wall WebPageCrawler.cc
/tmp/ccoLVzvo.o: In function `main':
WebPageCrawler.cc:(.text+0x28): undefined reference to `std::cout'
WebPageCrawler.cc:(.text+0x2d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
...even more errors...

正如您所看到的,编译器甚至无法找到stdlibs,而其他引用的库awesomium(无头浏览器)也无法使用。但是,相应的库可以在/usr/lib中找到。所以,一定有其他错误,但我不知道它可能是什么。

我的linux版本是

uname -a 
Linux Ubuntu-1204-precise-64-minimal 3.2.0-39-generic

我会帮助你。 THX。

更新: 使用g ++时我得到:

g++ -o WebPageCrawler -lawesomium-1-7 -Wall WebPageCrawler.cc
Unable to exec g++.real: No such file or directory

然而,在另一台机器上我使用gcc而不是g ++,它在那里工作正常。

UPDATE2: 好的,现在我能够解决stdlibs解决的问题。我通过进一步安装来做到这一点:

apt-get install build-essential g++

然而,现在仍然没有找到awesomium libs:

/opt/AwesomiumCrawler # g++ -v  -o WebPageCrawler -lawesomium-1-7 -Wall WebPageCrawler.cc
Using built-in specs.
COLLECT_GCC=g++.real
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
COLLECT_GCC_OPTIONS='-v' '-o' 'WebPageCrawler' '-Wall' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.6/cc1plus -quiet -v -imultilib . -imultiarch x86_64-linux-gnu -D_GNU_SOURCE WebPageCrawler.cc -quiet -dumpbase WebPageCrawler.cc -mtune=generic -march=x86-64 -auxbase WebPageCrawler -Wall -version -fstack-protector -o /tmp/ccGGfqAI.s
GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127439
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.6
 /usr/include/c++/4.6/x86_64-linux-gnu/.
 /usr/include/c++/4.6/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.6/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127439
Compiler executable checksum: 65b5171ac1bd7b3f07dbea6bdb24be3d
COLLECT_GCC_OPTIONS='-v' '-o' 'WebPageCrawler' '-Wall' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as --64 -o /tmp/cctijQGE.o /tmp/ccGGfqAI.s
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'WebPageCrawler' '-Wall' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.6/collect2 --sysroot=/ --build-id --no-add-needed --as-needed --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o WebPageCrawler /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -lawesomium-1-7 /tmp/cctijQGE.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o
/tmp/cctijQGE.o: In function `main':
WebPageCrawler.cc:(.text+0x8d): undefined reference to `Awesomium::WebConfig::WebConfig()'
WebPageCrawler.cc:(.text+0xc7): undefined reference to `Awesomium::WebString::operator=(Awesomium::WebString const&)'
WebPageCrawler.cc:(.text+0xd6): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0xe5): undefined reference to `Awesomium::WebCore::Initialize(Awesomium::WebConfig const&)'
WebPageCrawler.cc:(.text+0x140): undefined reference to `Awesomium::WebURL::WebURL(Awesomium::WebString const&)'
WebPageCrawler.cc:(.text+0x14c): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x1ed): undefined reference to `Awesomium::WebString::CreateFromUTF8(char const*, unsigned int)'
WebPageCrawler.cc:(.text+0x203): undefined reference to `Awesomium::WebString::CreateFromUTF8(char const*, unsigned int)'
WebPageCrawler.cc:(.text+0x23c): undefined reference to `Awesomium::JSValue::ToString() const'
WebPageCrawler.cc:(.text+0x259): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x27b): undefined reference to `Awesomium::WebCore::Shutdown()'
WebPageCrawler.cc:(.text+0x28c): undefined reference to `Awesomium::JSValue::~JSValue()'
WebPageCrawler.cc:(.text+0x298): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x2a4): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x2b0): undefined reference to `Awesomium::WebURL::~WebURL()'
WebPageCrawler.cc:(.text+0x2dd): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x2ee): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x2ff): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x310): undefined reference to `Awesomium::JSValue::~JSValue()'
WebPageCrawler.cc:(.text+0x321): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x332): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x343): undefined reference to `Awesomium::WebURL::~WebURL()'
/tmp/cctijQGE.o: In function `Update(int)':
WebPageCrawler.cc:(.text+0x372): undefined reference to `Awesomium::WebCore::instance()'
/tmp/cctijQGE.o: In function `Awesomium::ToString(Awesomium::WebString const&)':
WebPageCrawler.cc:(.text._ZN9Awesomium8ToStringERKNS_9WebStringE[Awesomium::ToString(Awesomium::WebString const&)]+0x25): undefined reference to `Awesomium::WebString::IsEmpty() const'
WebPageCrawler.cc:(.text._ZN9Awesomium8ToStringERKNS_9WebStringE[Awesomium::ToString(Awesomium::WebString const&)]+0x4d): undefined reference to `Awesomium::WebString::ToUTF8(char*, unsigned int) const'
WebPageCrawler.cc:(.text._ZN9Awesomium8ToStringERKNS_9WebStringE[Awesomium::ToString(Awesomium::WebString const&)]+0x75): undefined reference to `Awesomium::WebString::ToUTF8(char*, unsigned int) const'
/tmp/cctijQGE.o: In function `Awesomium::WSLit(char const*)':
WebPageCrawler.cc:(.text._ZN9Awesomium5WSLitEPKc[Awesomium::WSLit(char const*)]+0x2d): undefined reference to `Awesomium::WebString::CreateFromUTF8(char const*, unsigned int)'
/tmp/cctijQGE.o: In function `Awesomium::WebConfig::~WebConfig()':
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x19): undefined reference to `Awesomium::WebStringArray::~WebStringArray()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x29): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x39): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x49): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x59): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x69): undefined reference to `Awesomium::WebString::~WebString()'
/tmp/cctijQGE.o:WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x79): more undefined references to `Awesomium::WebString::~WebString()' follow
collect2: ld returned 1 exit status

如前所述,图书馆位于

/usr/lib # ls -l *awe*
-rwxr-xr-x 1 root root     8032 Feb 12 18:49 awesomium_process
lrwxrwxrwx 1 root root       21 Feb 12 18:49 libawesomium-1-7.so -> libawesomium-1-7.so.2
lrwxrwxrwx 1 root root       23 Feb 12 18:49 libawesomium-1-7.so.2 -> libawesomium-1-7.so.2.0
-rwxr-xr-x 1 root root 63475481 Feb 12 18:49 libawesomium-1-7.so.2.0

1 个答案:

答案 0 :(得分:4)

编译C ++代码的命令是g++,而不是gcc

它们都是同一个集合的一部分,但g++命令增加了一些额外的选项;特别是,它隐含地链接了C ++标准库。

使用-c进行编译时,为了生成一个目标文件而不调用链接器,它可能并不重要 - 但是你要生成一个可执行文件,这意味着链接器需要知道对它的依赖性。 C ++标准库。

更新:现在您已更新了问题:您可能需要安装g++(在您的系统上apt-get install build-essential g++)。

现在您遇到了另一个问题:g++无法找到“awesomium”库。这些库位于/usr/lib中,因此您无需指定-L选项。问题是-l选项需要跟随依赖于它的文件。

链接器按顺序处理其命令行参数,跟踪仍需要解析的符号,并解析稍后处理的对象或库中的任何未解析符号。

所以而不是:

g++ -o WebPageCrawler -lawesomium-1-7 -Wall WebPageCrawler.cc

尝试:

g++ -Wall WebPageCrawler.cc -lawesomium-1-7 -o WebPageCrawler

特定的顺序不是强制性的,但它应该有效。