繁体   English   中英

在Linux上编译C ++代码。 需要使用gcc / 4.7.2。 找不到标准库

[英]Compiling C++ code on Linux. Need to use gcc/4.7.2. Can't locate standard libraries

就处理编译/链接错误而言,我是一个新手。

我正在使用大型C ++代码(也有一些C文件)。 我已经成功地在Mac上运行它,用g ++编译。 现在我需要在基于Linux的集群上运行它,因为它在我的Mac上太慢了。 代码包含我必须编译的几个库,以及我自己使用库的代码。

我可以使用默认的g ++编译器编译集群上的所有代码。 然而,遗憾的是,我发现我需要使用gcc / 4.7.2进行编译,以便代码可以与群集上的其他软件一起使用。 我一直在努力编译和链接错误。 到目前为止,它们都与C ++与C的问题有关。例如,我不得不在某些C文件中添加“extern”。 我不得不将包含从C ++改为C头。

我的问题似乎是一个特定的库(我已经成功处理了所有其他库)。 它编译在其目录中。 但是当我进入我的运行目录时,我得到了各种错误,这些错误似乎与构成此问题库的代码有关。 我的猜测是,他们主要与找不到标准库有关。 我只是不明白我的包含有什么问题,如果有人可以看一下我的makefile中的库,我会非常感激。 这个库正式基于“C ++”,但它的文件中似乎确实有很多C风格的代码。

有太多的错误(页面)和太多的代码发布一切。 我希望我发布的内容已经足够,如果能有所帮助,可以添加它。 我无法准确找到他们在我的代码中的来源,因为他们非常神秘; 例如:

Code.cpp :(。text + 0x35):对`std :: cout'的未定义引用

我的makefile include和编译器选项如下。 我最初使用QT在Mac上创建了这个。 我修改它以使用gcc / 4.7.2上的Linux集群。 所以它完全有可能是一团糟。

我先做(终端命令行):

模块加载gcc / 4.7.2

然后makefile是:

CC = gcc

DEFINES = -DIPMGEMPLUGIN -DNOPARTICLEARRAY -D__unix

CFLAGS = -c -g -O2 -pedantic -fno-nonansi-builtins -D__unix -m64

CXXFLAGS = -pipe -O2 -Wall -W -fPIC $(DEFINES)-lstdc ++ -m64

INCPATH = -I。 \\

  -I/mounts/apps/gcc/4.7.2/ \\ -I/mounts/apps/gcc/4.7.2/bin/ \\ -I/mounts/apps/gcc/4.7.2/bin/x86_64-unknown-linux-gnu/4.7.2 \\ -I/mounts/apps/gcc/4.7.2/lib64 \\ -I/mounts/apps/gcc/4.7.2/bin/include \\ -I/mounts/apps/gcc/4.7.2/bin/include/c++ \\ -I/mounts/apps/gcc/4.7.2/4.7.2/bin/include/c++/4.7.2 \\ 

AR = ar cq RANLIB = ranlib -s TARGET = mylib.a

.SUFFIXES:.o .c .cpp .cc .cxx .C

.cpp.o:$(CC)-c $(CXXFLAGS)$(INCPATH)-o“$ @”“$ <”

.cc.o:$(CC)-c $(CXXFLAGS)$(INCPATH)-o“$ @”“$ <”

.cxx.o:$(CC)-c $(CXXFLAGS)$(INCPATH)-o“$ @”“$ <”

.Co:$(CC)-c $(CXXFLAGS)$(INCPATH)-o“$ @”“$ <”

.co:$(CC)-c $(CFLAGS)$(INCPATH)-o“$ @”“$ <”

现在我得到的错误种类:

Code.o:在函数_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.part.8': Code.cpp:(.text+0x12): undefined reference to std :: basic_ios> :: clear(std :: _ Ios_Iostate)'Code.o:在函数_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.constprop.101': Code.cpp:(.text+0x35): undefined reference to std :: cout'Code.cpp :(。text + 0x3a):未定义引用`std :: basic_ostream>&std :: __ ostream_insert

(std :: basic_ostream>&,char const *,long)'Code.cpp :(。text + 0x3f):对std::cout' Code.cpp:(.text+0x49): undefined reference to未定义引用std::cout' Code.cpp:(.text+0x49): undefined reference to std的std::cout' Code.cpp:(.text+0x49): undefined reference to : :cout'Code.cpp :(。text + 0x53):对std::cout' Code.o: In function未定义引用std::cout' Code.o: In function _ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode.constprop.99':Code.cpp :(。text + 0x93):对std::basic_filebuf<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode)' Code.o: In function未定义引用std::basic_filebuf<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode)' Code.o: In function _ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode.constprop.96':Code.cpp :(。text + 0x103 ):对std::ios_base::ios_base()' Code.cpp:(.text+0x10b): undefined reference to未定义引用std::ios_base::ios_base()' Code.cpp:(.text+0x10b): undefined reference to对std :: basic_ios的vtable的std::ios_base::ios_base()' Code.cpp:(.text+0x10b): undefined reference to 'Code.cpp :(。text + 0x11b):undefined reference to VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x15d): undefined reference to std :: basic_iostream的VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x15d): undefined reference to > :: basic_iostream() 'Code.cpp :(。text + 0x16c): vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x174): undefined reference to未定义引用 vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x174): undefined reference to对std :: basic_stringstream,std :: allocator>'代码的vtable的vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x174): undefined reference to 。 cpp :(。text + 0x17c): vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x184): undefined reference to未定义引用vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x184): undefined reference to对std :: basic_streambuf>'的vtable的vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x184): undefined reference to

进一步说:

gl3.cpp :(。text + 0x18d):未定义引用`operator new [](unsigned long)'

gl3.cpp :(。text + 0x1a1):未定义引用`operator new [](unsigned long)'

gl3.cpp :(。text + 0x1b5):未定义引用`operator new [](unsigned long)'

gl3.cpp :(。text + 0x1c9):未定义引用`operator new [](unsigned long)'

gl3.cpp :(。text + 0x1dd):未定义引用`operator new [](unsigned long)'

/data/place/number/account/CodeDirectory/../ProblemLibraryDirectory/libProblem.a(gl3.o):在函数Other::free_internal()': gl3.cpp:(.text+0x251): undefined reference to operator删除'gl3.cpp :(。text + 0x262):...

这对任何人都有意义吗?

您正在使用C ++函数,例如newstd::*函数,因此必须使用C ++编译器进行编译(除非您将C编译版本与C ++库链接)。 GCC是一个C编译器,G ++是GNU C ++编译器,所以你应该使用G ++。

我在你的一条评论中看到,由于某种原因你必须使用GCC。 如果是这种情况,那么您将不得不从程序中删除所有特定于C ++的代码(例如std::*new / delete ),或者与C ++库链接。 但是,我认为您不应该使用GCC。 请解释为什么你必须使用GCC然后我们可能会进一步帮助你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM