Compiling a simple C++ example OSX

50 views
Skip to first unread message

Nathan Gleaves

unread,
Apr 27, 2015, 4:26:55 PM4/27/15
to cpp-dri...@lists.datastax.com
After such a fast response to my last question. I figure i would try again with what is probably a stupid question.

I have been trying to put together a proof of concept for c++ and Cassandra for an application i work on. The POC doesn't yet do anything useful but once all of the build problems are resolved. I suspect i will be able to make some significant progress. On to the build problems:

I built the cpp-driver project and installed it using make install.
I created a very simple Hello World project. All it does is include <cassandra.h> and then print out "hello, world"

If i remove the Cassandra linking from my CMake file, everything works, (as one might expect). But once i add in to linking to the Cassandra library, i cant get anything other than.


Scanning dependencies of target counts
[100%] Building CXX object CMakeFiles/counts.dir/main.cpp.o
Linking CXX executable counts
ld: library not found for -lcassandra
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [counts] Error 1
make[2]: *** [CMakeFiles/counts.dir/all] Error 2
make[1]: *** [CMakeFiles/counts.dir/rule] Error 2
make: *** [counts] Error 2



Here is my CMakeLists.txt file.
cmake_minimum_required(VERSION 3.1)
project(counts)

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(counts ${SOURCE_FILES})
include_directories(/usr/local/include)
LINK_DIRECTORIES(/usr/local/lib64)
TARGET_LINK_LIBRARIES(counts cassandra)

main.cpp:
#include <iostream>
#include <cassandra.h>
using namespace std;

int main() {
cout << "Hello, World!" << endl;
return 0;
}


I assume this is my fault. I am not very used to doing things in c++. It has been a node.js world for a while. I have found a couple of things mentioning RPATH for OSX but none of it has helped yet.


Any help would be greatly appreciated.

Michael Penick

unread,
Apr 28, 2015, 2:04:41 PM4/28/15
to cpp-dri...@lists.datastax.com
Maybe try:

LINK_DIRECTORIES(/usr/local/lib64)  --> LINK_DIRECTORIES(/usr/local/lib) 

Using cmake might be overkill for simple example. On Mac you can run: 

clang++ -o main main.cpp -lcassandra -L/usr/local/lib -I/usr/local/include 

to build your example.

Hope it helps.
Mike

To unsubscribe from this group and stop receiving emails from it, send an email to cpp-driver-us...@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages