我刚为cassandra安装了C / C ++驱动程序并试图从examples目录运行简单程序,但是
我无法解决此错误。 / usr / bin / ld:找不到-lcassandra
这是我的cassandra:
root@iWanUbuntu-1:~/connect_cassandra_cpp/cpp-driver/examples/simple# which cassandra
/usr/sbin/cassandra
这是CMakeLists.txt:
cmake_minimum_required(VERSION 2.6.4)
set(PROJECT_NAME_STR cassandra)
set(PROJECT_LIB_NAME ${PROJECT_NAME_STR})
set(PROJECT_LIB_NAME_TARGET ${PROJECT_LIB_NAME})
set(PROJECT_SOURCE_DIR /root/connect_cassandra_cpp/cpp-driver)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ".")
set(PROJECT_EXAMPLE_NAME simple)
file(GLOB EXAMPLE_SRC_FILES ${PROJECT_SOURCE_DIR}/examples/simple/*.c)
include_directories(${INCLUDES})
add_executable(${PROJECT_EXAMPLE_NAME} ${EXAMPLE_SRC_FILES})
target_link_libraries(${PROJECT_EXAMPLE_NAME} ${PROJECT_LIB_NAME_TARGET} ${CASS_LIBS})
set_property(TARGET ${PROJECT_EXAMPLE_NAME} APPEND PROPERTY COMPILE_FLAGS ${EXAMPLE_C_FLAGS})
这是自动生成的make文件命令:
root@iWanUbuntu-1:~/connect_cassandra_cpp/cpp-driver/examples/simple# make --just-print
/usr/bin/cmake -H/root/connect_cassandra_cpp/cpp-driver/examples/simple -B/root/connect_cassandra_cpp/cpp-driver/examples/simple --check-build-system
CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /root/connect_cassandra_cpp /cpp-driver/examples/simple/CMakeFiles /root/connect_cassandra_cpp/cpp-driver/examples/simple/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make -f CMakeFiles/simple.dir/build.make CMakeFiles/simple.dir/depend
cd /root/connect_cassandra_cpp/cpp-driver/examples/simple && /usr/bin/cmake -E
cmake_depends "Unix Makefiles" /root/connect_cassandra_cpp/cpp-driver/examples/simple /root/connect_cassandra_cpp/cpp-driver/examples/simple
/root/connect_cassandra_cpp/cpp-driver/examples/simple /root/connect_cassandra_cpp/cpp-driver/examples/simple /root/connect_cassandra_cpp/cpp-driver/examples/simple/CMakeFiles/simple.dir/DependInfo.cmake --color=
make -f CMakeFiles/simple.dir/build.make CMakeFiles/simple.dir/build
/usr/bin/cmake -E cmake_echo_color --switch= --red --bold "Linking C executable simple"
/usr/bin/cmake -E cmake_link_script CMakeFiles/simple.dir/link.txt --verbose=
/usr/bin/cmake -E cmake_progress_report /root/connect_cassandra_cpp/cpp-driver/examples/simple/CMakeFiles 1
echo "Built target simple"
/usr/bin/cmake -E cmake_progress_start /root/connect_cassandra_cpp/cpp-driver/examples/simple/CMakeFiles 0
___
完整错误输出:
root@iWanUbuntu-1:~/connect_cassandra_cpp/cpp-driver/examples/simple# make
-- Configuring done
-- Generating done
-- Build files have been written to: /root/connect_cassandra_cpp/cpp-driver/examples/simple
Linking C executable simple
/usr/bin/ld: cannot find -lcassandra
collect2: error: ld returned 1 exit status
CMakeFiles/simple.dir/build.make:85: recipe for target 'simple' failed
make[2]: *** [simple] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/simple.dir/all' failed
make[1]: *** [CMakeFiles/simple.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2enter code here
编辑问题:Cassandra安装输出:
root@iWanUbuntu-1:~# sudo -E apt-get install cassandra
Reading package lists... Done
Building dependency tree
Reading state information... Done
cassandra is already the newest version.
The following packages were automatically installed and are no longer required:
fonts-dejavu-extra libatk-wrapper-java libatk-wrapper-java-jni libgif4 libgnomevfs2-0 libgnomevfs2-common libice-dev libntdb1 libpthread-stubs0-dev libsctp1 libsm-dev libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxt-dev lksctp-tools python-ntdb tzdata-java x11proto-core-dev x11proto-input dev x11proto-kb-dev xorg-sgml-doctools xtrans-dev
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.
root@iWanUbuntu-1:~# sudo -E apt-get install cassandra-devel
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package cassandra-devel
root@iWanUbuntu-1:~#
答案 0 :(得分:2)
我正在查看此项目的自述文件,您似乎克隆了代码部分https://github.com/datastax/cpp-driver/blob/master/README.md,但您还需要可执行文件。在可执行文件下有驱动程序和驱动程序开发,并且安装driver-dev.deb包将获得1.头文件2.共享库,编译器无法找到。通常,您的编译器告诉您它在/ usr / lib或usr / lib64文件夹中找不到libcassandra.so。这通常是在您安装驱动程序时,但忘记安装driver-devel软件包。 这里是devel包http://downloads.datastax.com/cpp-driver/ubuntu/ 或者如果你用apt-get安装cassandra,比如
apt-get install cassandra
尝试使用
获取开发部分 apt-get install cassandra-devel
修改强>
最终我从源手动编译并安装了驱动程序,然后编译examples / simple,因为其他解决方案(intalling cassandra-cpp-driver.rpm)没有解决整个线程。就这样做:
git clone https://github.com/datastax/cpp-driver.git
cd cpp-driver
mkdir build
cd build
cmake ..
make
sudo make install
cd ../examples/simple
gcc simple.c -L /usr/local/lib64 -l cassandra -I /usr/local/include -o simple.o
为我工作。另一方面,你可以在/ usr / lib64 /和/ usr / include中的cassandra.h中搜索libcassandra.so。(一些疯狂的扩展名)。如果只是将/usr/lib64/libcassandra.so符号链接到/usr/lib64/libcassandra.so.(某些疯狂的扩展名)并重新编译