程序将不再编译

时间:2011-11-11 21:06:04

标签: c++ compiler-construction linker makefile

我目前正在研究一种C ++,我在Mac上本地编辑但在Ubuntu服务器上运行。我总是确保代码在我的mac上编译,然后将其上传到服务器进行编译,在那里我必须使用makefile链接安装在我本地目录中的库。基本上,我编辑了我的代码的很大一部分,发现它在我的mac上编译,并将其上传到服务器进行编译,但它没有编译!幸运的是,我有一个代码的备份版本,所以我在服务器上尝试了,这也不会编译!在我最后一次知道我的代码在服务器上编译和现在之间,我知道他们运行了一些更新,但这就是我能想到的那些不同。作为参考,这是我的make文件:

LOCAL_INCLUDE = /home/schraiber/.local/include
LOCAL_LIB = /home/schraiber/.local/lib
CXXFLAGS = -I$(LOCAL_INCLUDE)
CXX_LDFLAGS = -L$(LOCAL_LIB) -lgsl -lm -lgslcblas -lpthread

CoalHMMgf: main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o ThreadData.h
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o -o CoalHMMgf
main.o: main.cpp IOUtilities.h parameters.h Algorithms.h Optimization.h probabilities.h ThreadData.h Data.h
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c main.cpp
IOutilities.o: IOUtilities.h IOUtilities.cpp parameters.h data.h
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c IOUtilities.cpp
parameters.o: parameters.h parameters.cpp
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c parameters.cpp
Algorithms.o: Algorithms.h Algorithms.cpp
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c Algorithms.cpp
Optimization.o: Optimization.h Optimization.cpp Algorithms.h parameters.h probabilities.h RNGUtilities.h ThreadData.h IOUtilities.h
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c Optimization.cpp
probabilities.o: probabilities.h probabilities.cpp parameters.h
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c probabilities.cpp
RNGUtilities.o: RNGUtilities.h RNGUtilities.cpp
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c RNGUtilities.cpp
Data.o: Data.h Data.cpp
        g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c Data.cpp

和错误:

g++ -I/home/schraiber/.local/include -L/home/schraiber/.local/lib -lgsl -lm -lgslcblas -lpthread main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o -o CoalHMMgf
main.o: In function `main':
main.cpp:(.text+0xbf1): undefined reference to `pthread_create'
main.cpp:(.text+0xd0e): undefined reference to `pthread_join'
Optimization.o: In function `my_df(gsl_vector const*, void*, gsl_vector*)':
Optimization.cpp:(.text+0x3149): undefined reference to `gsl_vector_alloc'
Optimization.cpp:(.text+0x316b): undefined reference to `gsl_vector_get'
Optimization.cpp:(.text+0x3180): undefined reference to `gsl_vector_set'
Optimization.cpp:(.text+0x31bc): undefined reference to `gsl_vector_get'
Optimization.cpp:(.text+0x31ec): undefined reference to `gsl_vector_set'
Optimization.cpp:(.text+0x323b): undefined reference to `gsl_vector_set'
Optimization.cpp:(.text+0x327e): undefined reference to `gsl_vector_set'
Optimization.cpp:(.text+0x32c9): undefined reference to `gsl_vector_set'
Optimization.o: In function `MHthreaded(void*)':
Optimization.cpp:(.text+0x3489): undefined reference to `gsl_rng_env_setup'
Optimization.cpp:(.text+0x3490): undefined reference to `gsl_rng_default'
Optimization.cpp:(.text+0x360b): undefined reference to `gsl_rng_uniform'
Optimization.cpp:(.text+0x3653): undefined reference to `gsl_ran_gaussian'
Optimization.cpp:(.text+0x3686): undefined reference to `gsl_ran_gaussian'
Optimization.cpp:(.text+0x377f): undefined reference to `gsl_rng_uniform'
RNGUtilities.o: In function `AllocRNG(gsl_rng*&, gsl_rng_type const*, int)':
RNGUtilities.cpp:(.text+0x9a): undefined reference to `gsl_rng_alloc'
RNGUtilities.cpp:(.text+0xba): undefined reference to `gsl_rng_set'
RNGUtilities.o: In function `FreeRNG(gsl_rng*&)':
RNGUtilities.cpp:(.text+0xe3): undefined reference to `gsl_rng_free'
collect2: ld returned 1 exit status
make: *** [CoalHMMgf] Error 1

并且只是为了验证gsl是否安装在本地目录中:

schraiber@trump:~/test_rsync$ ls ~/.local/lib
libbpp-core.a     libbpp-core.so.2.0.0  libbpp-seq.so.9      libgslcblas.a   libgslcblas.so.0      libgsl.so         pkgconfig
libbpp-core.so    libbpp-seq.a          libbpp-seq.so.9.1.0  libgslcblas.la  libgslcblas.so.0.0.0  libgsl.so.0       python2.7
libbpp-core.so.2  libbpp-seq.so         libgsl.a             libgslcblas.so  libgsl.la             libgsl.so.0.16.0
schraiber@trump:~/test_rsync$ ls ~/.local/include/
Bpp  gsl

有一点需要注意的是,我的程序也应该与Bpp链接,就我所知,这样做就好了。

2 个答案:

答案 0 :(得分:5)

你的“-lfoo”参数应该在你的“g ++”命令行中排在最后。因此,例如,在makefile中进行此更改:

CoalHMMgf: main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o ThreadData.h
        g++ $(CXXFLAGS) main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o -o CoalHMMgf $(CXX_LDFLAGS) 

答案 1 :(得分:0)

必须在链接行上定义库,以便不包含其他引用的库是最后一个。需要首先列出依赖于第二个库中的代码的库。它们必须在.o文件之后列出,否则假定.o文件是自包含的并且不需要库。