如何在g++;在Ubuntu上 我尝试在Ubuntu上用C++手动连接外部库。由于这是我的第一个C++项目,所以我缺少一些基本知识。 这是我的代码(尝试连接到spread):

如何在g++;在Ubuntu上 我尝试在Ubuntu上用C++手动连接外部库。由于这是我的第一个C++项目,所以我缺少一些基本知识。 这是我的代码(尝试连接到spread):,c++,ubuntu,C++,Ubuntu,据我所知,我需要链接一个库,我试着用-l链接 kristjan@kupo:~/thesis$ g++ -o example1 test.cpp -llibspread /usr/bin/ld: cannot find -llibspread collect2: ld returned 1 exit status 我也试过这个(我在黑暗中拍摄): 任何帮助都将不胜感激。正如@Mat所说,您应该使用-lspread并省略lib前缀。-lspread如果.so文件位于标准位置,则是正确的选择。您应该

据我所知,我需要链接一个库,我试着用-l链接

kristjan@kupo:~/thesis$ g++ -o example1 test.cpp -llibspread
/usr/bin/ld: cannot find -llibspread
collect2: ld returned 1 exit status
我也试过这个(我在黑暗中拍摄):


任何帮助都将不胜感激。

正如@Mat所说,您应该使用
-lspread
并省略
lib
前缀。

-lspread
如果.so文件位于标准位置,则是正确的选择。您应该跳过-llibspread-just use-lspread中的lib
user@computer:~/thesis$ g++ -o example1 test.cpp
/tmp/cczPLZQ0.o: In function `main':
test.cpp:(.text+0x39): undefined reference to `SP_connect'
collect2: ld returned 1 exit status
kristjan@kupo:~/thesis$ g++ -o example1 test.cpp -llibspread
/usr/bin/ld: cannot find -llibspread
collect2: ld returned 1 exit status
user@computer:~/thesis$ g++ -o example1 test.cpp $(pkg-config -cflags /usr/local/lib/libspread) $(pkg-config --libs /usr/local/lib/libspread)

-cflags: unknown option
Package /usr/local/lib/libspread was not found in the pkg-config search path.
Perhaps you should add the directory containing `/usr/local/lib/libspread.pc'
to the PKG_CONFIG_PATH environment variable
No package '/usr/local/lib/libspread' found
/tmp/ccU8GTC2.o: In function `main':
test.cpp:(.text+0x39): undefined reference to `SP_connect'
collect2: ld returned 1 exit status