简体   繁体   English

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

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

I am a bit of a newbie as far as dealing with compilation/linking errors. 就处理编译/链接错误而言,我是一个新手。

I'm working with a large C++ code (there are a few C files as well). 我正在使用大型C ++代码(也有一些C文件)。 I have successfully been running it on a Mac, compiled with g++. 我已经成功地在Mac上运行它,用g ++编译。 Now I need to run it on a Linux-based cluster because it is too slow on my Mac. 现在我需要在基于Linux的集群上运行它,因为它在我的Mac上太慢了。 The code consists of several libraries that I have to compile, plus my own code that uses the libraries. 代码包含我必须编译的几个库,以及我自己使用库的代码。

I can compile all of the code on the cluster using the default g++ compiler. 我可以使用默认的g ++编译器编译集群上的所有代码。 However, unfortunately, I have discovered that I need to compile with gcc/4.7.2 so that the code will work with other software on the cluster. 然而,遗憾的是,我发现我需要使用gcc / 4.7.2进行编译,以便代码可以与群集上的其他软件一起使用。 I have been working my way through compilation and linking errors. 我一直在努力编译和链接错误。 So far, they have all been related to issues with C++ versus C. For example, I have had to add "extern" in some of the C files. 到目前为止,它们都与C ++与C的问题有关。例如,我不得不在某些C文件中添加“extern”。 I have had to change includes from C++ to C headers. 我不得不将包含从C ++改为C头。

My problem seems to be with one particular library (I have successfully dealt with all the others). 我的问题似乎是一个特定的库(我已经成功处理了所有其他库)。 It compiles in its directory. 它编译在其目录中。 But when I go to my run directory, I get all kinds of errors that seem to be related to the code that makes up this problem library. 但是当我进入我的运行目录时,我得到了各种错误,这些错误似乎与构成此问题库的代码有关。 My guess is that they are mostly related to not finding the standard libraries. 我的猜测是,他们主要与找不到标准库有关。 I just don't understand how there is a problem with my includes and would really appreciate it if someone could take a look at what I have in my makefile for this library. 我只是不明白我的包含有什么问题,如果有人可以看一下我的makefile中的库,我会非常感激。 This library is officially based on "C++," but there does seem to be a lot of C-style code in its files. 这个库正式基于“C ++”,但它的文件中似乎确实有很多C风格的代码。

There are far too many errors (pages) and far too much code to post everything. 有太多的错误(页面)和太多的代码发布一切。 I hope that what I have posted is sufficient and can add to it if that would help. 我希望我发布的内容已经足够,如果能有所帮助,可以添加它。 I can't locate exactly where they are coming from in my code because they are very cryptic; 我无法准确找到他们在我的代码中的来源,因为他们非常神秘; for example: 例如:

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

My makefile include and compiler options are below. 我的makefile include和编译器选项如下。 I originally created this on my Mac using QT. 我最初使用QT在Mac上创建了这个。 I modified it to work with the Linux cluster on gcc/4.7.2. 我修改它以使用gcc / 4.7.2上的Linux集群。 So it is entirely possible that it is a bit of a mess. 所以它完全有可能是一团糟。

First I do (command line in terminal): 我先做(终端命令行):

module load gcc/4.7.2 模块加载gcc / 4.7.2

Then the makefile is: 然后makefile是:

CC = gcc CC = gcc

DEFINES = -DIPMGEMPLUGIN -DNOPARTICLEARRAY -D__unix DEFINES = -DIPMGEMPLUGIN -DNOPARTICLEARRAY -D__unix

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

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

INCPATH = -I. 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 AR = ar cq RANLIB = ranlib -s TARGET = mylib.a

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

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

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

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

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

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

Now the kinds of errors I'm getting: 现在我得到的错误种类:

Code.o: In function _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.part.8': Code.cpp:(.text+0x12): undefined reference to std::basic_ios >::clear(std::_Ios_Iostate)' Code.o: In function _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.constprop.101': Code.cpp:(.text+0x35): undefined reference to std::cout' Code.cpp:(.text+0x3a): undefined reference to `std::basic_ostream >& std::__ostream_insert 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): undefined reference to std::cout' Code.cpp:(.text+0x49): undefined reference to std::cout' Code.cpp:(.text+0x53): undefined reference to std::cout' Code.o: In function _ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode.constprop.99': Code.cpp:(.text+0x93): undefined reference to 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): undefined reference to std::ios_base::ios_base()' Code.cpp:(.text+0x10b): undefined reference to vtable for std::basic_ios ' 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 >::basic_iostream()' Code.cpp:(.text+0x16c): 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_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 vtable for std::basic_stringstream, std::allocator >' Code.cpp:(.text+0x17c): undefined reference to vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' Code.cpp:(.text+0x184): undefined reference to vtable for std::basic_streambuf >' 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

And further on: 进一步说:

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

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

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

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

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

/data/place/number/account/CodeDirectory/../ProblemLibraryDirectory/libProblem.a(gl3.o): In function Other::free_internal()': gl3.cpp:(.text+0x251): undefined reference to operator delete' gl3.cpp:(.text+0x262): ... /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):...

Does any of this mean anything to anyone? 这对任何人都有意义吗?

You are using C++ functions such as new and std::* functions, therefore you must compile using a C++ compiler (unless you link the C compiled version with the C++ libraries). 您正在使用C ++函数,例如newstd::*函数,因此必须使用C ++编译器进行编译(除非您将C编译版本与C ++库链接)。 GCC is a C compiler and G++ is the GNU C++ compiler, so you should use G++. GCC是一个C编译器,G ++是GNU C ++编译器,所以你应该使用G ++。

I saw in one of your comments that for some reason you had to use GCC. 我在你的一条评论中看到,由于某种原因你必须使用GCC。 If this is the case then you will have to remove all C++ specific code from your program (eg std::* and new / delete ), or link with the C++ libraries. 如果是这种情况,那么您将不得不从程序中删除所有特定于C ++的代码(例如std::*new / delete ),或者与C ++库链接。 However I don't see any reason that you should have to use GCC. 但是,我认为您不应该使用GCC。 Please explain why you have to use GCC then we may be able to help you further. 请解释为什么你必须使用GCC然后我们可能会进一步帮助你。

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

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