我有点咸菜。我似乎无法弄清楚问题出在哪里:我有一个简单的测试文件(test.cpp):
#include <RMF.h>
#include <RMF/FileHandle.h>
#include <iostream>
int main(){
RMF::FileHandle fh;
fh = RMF::create_rmf_file("/home/kkarius/junk/test_rmfs/run_109_frame_6963.rmf3");
std::cout << "yep" << std::endl;
return 0;
}
然后我使用以下两个命令来编译和链接我的测试文件。
g++ -Wall -I./include -c test.cpp
g++ -v -g -L./lib64/ -o test test.o -lRMF
我链接的较旧版本和文件是:
bash-4.2$ ls lib64/
cmake libimp_display.so libimp_isd.so.0 libimp_modeller.so libimp_pepdock.so.0 libimp_scratch.so
libimp_algebra.so libimp_display.so.0 libimp_kernel.so libimp_modeller.so.0 libimp_pmi.so libimp_scratch.so.0
libimp_algebra.so.0 libimp_domino.so libimp_kernel.so.0 libimp_mpi.so libimp_pmi.so.0 libimp_statistics.so
libimp_atom.so libimp_domino.so.0 libimp_kinematics.so libimp_mpi.so.0 libimp_rmf.so libimp_statistics.so.0
libimp_atom.so.0 libimp_em.so libimp_kinematics.so.0 libimp_multi_state.so libimp_rmf.so.0 libimp_symmetry.so
libimp_benchmark.so libimp_em.so.0 libimp_kmeans.so libimp_multi_state.so.0 libimp_rotamer.so libimp_symmetry.so.0
libimp_benchmark.so.0 libimp_example.so libimp_kmeans.so.0 libimp_npc.so libimp_rotamer.so.0 libimp_test.so
libimp_container.so libimp_example.so.0 libimp_misc.so libimp_npc.so.0 libimp_saxs.so libimp_test.so.0
libimp_container.so.0 libimp_foxs.so libimp_misc.so.0 libimp_parallel.so libimp_saxs.so.0 libRMF.so
libimp_core.so libimp_foxs.so.0 libimp_mmcif.so libimp_parallel.so.0 libimp_score_functor.so python2.7
libimp_core.so.0 libimp_isd.so libimp_mmcif.so.0 libimp_pepdock.so libimp_score_functor.so.0
和
bash-4.2$ ls include/
IMP IMP.h RMF RMF.h
虽然compile命令运行良好,但链接却没有:
bash-4.2$ g++ -v -g -L./lib64/ -o test test.o -lRMF
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --disable-multilib --enable-languages=c,c++
Thread model: posix
gcc version 7.3.0 (GCC)
COMPILER_PATH=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/:/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/:/usr/local/libexec/gcc/x86_64-pc-linux-gnu/:/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/:/usr/local/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/:/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-g' '-L./lib64/' '-o' 'test' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/collect2 -plugin /usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/liblto_plugin.so -plugin-opt=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccKz3qw4.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test /lib/../lib64/crt1.o /lib/../lib64/crti.o /usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/crtbegin.o -L./lib64/ -L/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0 -L/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../.. test.o -lRMF -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/crtend.o /lib/../lib64/crtn.o
test.o: In function `main':
test.cpp:(.text+0x45): undefined reference to `RMF::create_rmf_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status
bash-4.2$ g++ -g -o test test.o lib64/libRMF.so
test.o: In function `main':
test.cpp:(.text+0x45): undefined reference to `RMF::create_rmf_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit statusexec/gcc/x86_64-pc-linux-gnu/7.3.0/liblto_plugin.so -plugin-opt=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccKz3qw4.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test /lib/../lib64/crt1.o /lib/../lib64/crti.o /usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/crtbegin.o -L./lib64/ -L/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0 -L/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../.. test.o -lRMF -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/lib/gcc/x86_64-pc-linux-gnu/7.3.0/crtend.o /lib/../lib64/crtn.o
test.o: In function `main':
test.cpp:(.text+0x45): undefined reference to `RMF::create_rmf_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status
bash-4.2$ g++ -g -o test test.o lib64/libRMF.so
test.o: In function `main':
test.cpp:(.text+0x45): undefined reference to `RMF::create_rmf_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status
因此,我查看了libRMF.so文件,在其中找到了所需的方法:
bash-4.2$ nm lib64/libRMF.so | grep create_rmf_file
00000000009fd6e2 T _ZN3RMF15create_rmf_fileESs
现在我处于一种状态,我认为我做对了所有事情,但显然我没有做!有人可以指出我的错误吗?
一切顺利 凯