CMake does not include direct support for 0mq, and 0mq does not include direct support for CMake. But 0mq supports pkg-config , and we can use this to help us. Since you mentioned that you are on Ubuntu 14.04, make sure you do sudo apt-get install libzmq3-dev to install the 0mq libraries, headers, and the pkg-config .pc .
Then use the following CMakeLists.txt , which I changed from your version above. (I commented on all my inline changes.)
#
Now you can make complete your project.
❯ make [ 50%] Building CXX object CMakeFiles/test2.dir/main.cpp.o [100%] Linking CXX executable test2 [100%] Built target test2
If you want to see what happens under the hood, do a detailed make.
❯ make VERBOSE=1 /usr/bin/cmake -H/home/nega/foo -B/home/nega/foo/build --check-build-system CMakeFiles/Makefile.cmake 0 /usr/bin/cmake -E cmake_progress_start /home/nega/foo/build/CMakeFiles /home/nega/foo/build/CMakeFiles/progress.marks make -f CMakeFiles/Makefile2 all make[1]: Entering directory '/home/nega/foo/build' make -f CMakeFiles/test2.dir/build.make CMakeFiles/test2.dir/depend make[2]: Entering directory '/home/nega/foo/build' cd /home/nega/foo/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/nega/foo /home/nega/foo /home/nega/foo/build /home/nega/foo/build /home/nega/foo/build/CMakeFiles/test2.dir/DependInfo.cmake --color= make[2]: Leaving directory '/home/nega/foo/build' make -f CMakeFiles/test2.dir/build.make CMakeFiles/test2.dir/build make[2]: Entering directory '/home/nega/foo/build' [ 50%] Building CXX object CMakeFiles/test2.dir/main.cpp.o /usr/bin/c++ -std=gnu++11 -o CMakeFiles/test2.dir/main.cpp.o -c /home/nega/foo/main.cpp [100%] Linking CXX executable test2 /usr/bin/cmake -E cmake_link_script CMakeFiles/test2.dir/link.txt --verbose=1 /usr/bin/c++ CMakeFiles/test2.dir/main.cpp.o -o test2 /usr/lib/x86_64-linux-gnu/libzmq.so make[2]: Leaving directory '/home/nega/foo/build' [100%] Built target test2 make[1]: Leaving directory '/home/nega/foo/build' /usr/bin/cmake -E cmake_progress_start /home/nega/foo/build/CMakeFiles 0
If you look at the compilation line, you will notice that
- Added support for C ++ 11 (with the flag
-std=gnu++11 ) - There is no flag
-I/path/to/zmq . This is because Ubuntu resets zmq.hpp to /usr/include and CMake is smart enough to know that this is the default path, so it does nothing
If you look at the link line, you will notice that libzmq.so has been enabled through the full path. Some people don't like this (including me) and prefer -L/lib/dir -lmylib . Using the full path is the “CMake path”, and you really appreciate it when you grow with CMake and use it for larger and more complex projects (you might not like it anyway).
Also note that since you are on Ubuntu, we could trick and use dpkg -L libzmq3-dev to find the locations of the files we are interested in, and then add them to the original CMAKE_CXX_FLAGS line, but this is a trick and much more, and do not tolerate.
source share