Clion can't find a library installed using homebrew - macos

I am working on MacOS and using homebrew to install libraries. The library that I am trying to get working is freeImage which installed just fine using homebrew.
In Clion to link library I edited CmakeLists.txt file to contain:
target_link_libraries(Tutorial_2 freeimage)
I get the following output when trying to compile:
ld: library not found for -lfreeimage
Never had issues with this using linux and not sure what i'm doing wrong here?

First, you need to find the installation path of this library by brew info freeimage. My example is /usr/local/Cellar/freeimage/3.18.0:
freeimage: stable 3.18.0 (bottled), HEAD
Library for FreeImage, a dependency-free graphics library
https://sourceforge.net/projects/freeimage
/usr/local/Cellar/freeimage/3.18.0 (16 files, 29.9MB) *
then, modify your CMakeLists.txt to fix the problem:
cmake_minimum_required(VERSION 3.22)
project(libuv_clion C)
set(FREE_IMAGE_DIR /usr/local/Cellar/freeimage/3.18.0) # set the lib path
include_directories(${FREE_IMAGE_DIR}/include/) # include the lib
link_directories(${FREE_IMAGE_DIR}/lib/) # link the lib
set(CMAKE_C_STANDARD 11)
add_executable(libuv_clion main.c)
target_link_libraries(libuv_clion freeimage)

Related

compiling SFML with cmake and mingw under windows

When i try to run cmake to build a project where i include the SFML library i get the following Error: SFML found but version too low (requested: 2.4, found: 1.x.x)
I downloaded only the source of the newest Version of the library (SFML-2.4.2). I than run cmake (with MinGW Makefiles) And build the binaries into the same folder.
I copied the FindSFML into an subfolder of my project.
After that i had the following folder structure
SFML-2.4.2\
cmake\
Modules\
FindSFML.cmake
CMakeFiles
doc
...
include
lib
src
..
sfml-games\
tetris\
cmake_modules\
FindSFML.cmake
CMakeLists.txt
main.cpp
tetris-build
...
My CMakeLists.txt contains the following stuff:
project(Tetris)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
Find_package(SFML 2 REQUIRED system window graphics network audio)
include_directories(${SFML_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARY})
I found that in cmake the entry CMAKE_INSTALL_PREFIX (which i dont get) is set to C:\Program Files (x86)\SFML so i put the library and the lib of SFML into C:\Program Files (x86)\SFML. (what is that CMAKE_INSTALL_PREFIX and should i realy always copy the library and lib folders into my C:\Program Files (x86)\ ??). Now my cmake runs through but when i try to compile the code i get a lot of undifined references to '_imp__....'
By the way on linux i just installed SFML via sudo apt-get install libsfml-dev and it works out of the box.
You're confusing things. CMAKE_INSTALL_PREFIX is the default location where to put SFML when you build the install target (i.e. running make install). This has nothing to do with your other issues.
You don't have to install SFML (or any other library) somewhere under C:\Program Files. That's completely up to you.
What I found to be rather neat is installing MinGW to C:\usr (or creating a symlink to your installation folder) and also use that path for CMAKE_INSTALL_PREFIX when building SFML.
This way MinGW should behave pretty much the way you're used to from Linux (i.e. not having to specify paths for include dir or libraries etc.).
As for your undefined reference errors, you should create a new question only asking for these (and then include at least a few of them), as they have nothing to do with the installation directory.
Right now I can only guess, but it's most likely due to you using the wrong CMake variables for the linker. You won't notice this on Linux, since SFML will be in the default search path (which will also happen if you use C:\usr as described above).
To try fixing this, use this line:
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

Cygwin: "boost/filesystem.hpp: No such file or directory compilation terminated."

I get this error when I'm using Cygwin on a "makefile":
"boost/filesystem.hpp: No such file or directory compilation terminated."
This is everything that's inside the "makefile":
mnisten: src/main.cpp g++ -Wall -O2 -lboost_filesystem-mt -std=c++0x -o mnisten src/main.cpp
And inside the "main.cpp" file, this is the line of code that the error message is referring to:
#include <boost/filesystem.hpp>
First I tried to put the "boost" folder (containing "filesystem.hpp") inside the "src" folder, but the error message was unchanged, I still got the same error message.
Then I changed the "include" code inside "main.cpp" to:
#include <filesystem.hpp>
I also copied the "filesystem.hpp" file into the root of the "src" folder, and surprisingly this worked. I got a new error, but I got past the "include" part.
I find it very confusing that it I get an error when the file is in a folder, but when it is in the root of the "src" folder it works.
Any suggestions on how I can get it to work when the file is inside the "boost" folder?
(I downloaded the the "filesystem.hpp" since it was not included)
To find the cygwin package that contains a given file you can use cygcheck -p
$ cygcheck -p boost/filesystem.hpp
Found 6 matches for boost/filesystem.hpp
libboost-devel-1.60.0-1 - libboost-devel: Boost C++ libraries (installed binaries and support files)
libboost-devel-1.60.0-2 - libboost-devel: Boost C++ libraries (installed binaries and support files)
mingw64-i686-boost-1.60.0-1 - mingw64-i686-boost: Boost C++ libraries for Win32 toolchain (installed binaries and support files)
mingw64-i686-boost-1.60.0-2 - mingw64-i686-boost: Boost C++ libraries for Win32 toolchain (installed binaries and support files)
mingw64-x86_64-boost-1.60.0-1 - mingw64-x86_64-boost: Boost C++ libraries for Win64 toolchain (installed binaries and support files)
mingw64-x86_64-boost-1.60.0-2 - mingw64-x86_64-boost: Boost C++ libraries for Win64 toolchain (installed binaries and support files)
so you need to install libboost-devel as you are not crosscompiling for mingw64.
Similar for
$ cygcheck -p opencv/cv.hpp
Found 1 matches for opencv/cv.hpp
libopencv-devel-2.4.11-1 - libopencv-devel: Real-time computer vision library (development) (installed binaries and support files)
Probably you don't have any boost installed in your system. I got this error and solved by installing it.
sudo apt-get install libboost-all-dev

ROS Kinetic Opencv3 Cmake error

I try to use opencv3 with ROS kinetic binary packages but when I use catkin_make I have an error that I can't fix !
Result of rospack find opencv3 : /opt/ros/kinetic/share/opencv3
Error: CMake Warning at /opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:76 (find_package):
Could not find a package configuration file provided by "opencv3" with any
of the following names:
opencv3Config.cmake
opencv3-config.cmake
Add the installation prefix of "opencv3" to CMAKE_PREFIX_PATH or set
"opencv3_DIR" to a directory containing one of the above files. If
"opencv3" provides a separate development package or SDK, be sure it has
been installed.
Thanks for your help
If you want to use OpenCV 3 in ROS Kinetic, you only need to do the following in your CMakeLists.txt: find_package(OpenCV REQUIRED), because OpenCV 3 is the default in ROS Kinetic. Pay attention to the capitalization, it must be OpenCV (i.e. find_package(opencv) is not going to work!)
References: Section 1.2 and 2 at http://wiki.ros.org/opencv3
I used this post for opencv2 :
[ROS hydro opencv2 linking error during 'catkin_make'
I put in Cmake:
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})

GMP & MPFR not found by cmake, but are installed

I'm trying to compile the plll library which require boost, GMP and MPFR on mac os X 10.11.
I've installed boost, GMP and MPFR by homebrew, then i've launched cmake in a dir build in plll, but I get that error :
By not providing "FindMPFR.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "MPFR", but
CMake did not find one.
Could not find a package configuration file provided by "MPFR" with any of
the following names:
MPFRConfig.cmake
mpfr-config.cmake
Add the installation prefix of "MPFR" to CMAKE_PREFIX_PATH or set
"MPFR_DIR" to a directory containing one of the above files. If "MPFR"
provides a separate development package or SDK, be sure it has been
installed.
And the same for GMP if I change the order of GMP and MPFR in the Librairies.txt used by cmake.
After that i've install the librairies by hand and they are in/usr/local/include. The make check of GMP is perfect so I guess that the installation is ok.
But still the same error message. I've also tried to add a FindMPFR.cmake file but no change at all.
Here is the part of the Libraries.txt which is concerned:
find_package(MPFR REQUIRED)
include_directories(${MPFR_INCLUDES})
if(NOT MPFR_FOUND)
message(FATAL_ERROR "Could not find MPFR!")
endif(NOT MPFR_FOUND)
set(libraries ${libraries} ${MPFR_LIBRARIES})
set(libraries_shared ${libraries_shared} ${MPFR_LIBRARIES})
find_package(GMP REQUIRED)
include_directories(${GMP_INCLUDE_DIR})
if(NOT (GMP_INCLUDE_DIR AND GMP_LIBRARIES))
message(FATAL_ERROR "Could not find GMP!")
endif(NOT (GMP_INCLUDE_DIR AND GMP_LIBRARIES))
set(libraries ${libraries} ${GMP_LIBRARIES})
set(libraries_shared ${libraries_shared} ${GMP_LIBRARIES})
The strange part of that is that I've no problem with Boost...

Linking Boost Filesystem in XCode 3.2 (MacPorts)

I am using XCode 3.2 and have installed boost using the MacPorts project (both release and debug) however I am at a loss to get my application to link with boost::filesystem
I have set my library search path to /opt/local/lib but I still get unresolved references when linking the project.
I noticed in another post to add -lboost_system to the "other linker flags" but when I do this I get - libboost_system.dylib, file was built for unsupported file format which is not the architecture being linked (i386).
Is MacPorts not installing the right libraries or am I missing something else?
Martin
You didn't indicate what OS version you are build it with. My guess is MacPort defaults to x64 when building and installing ports. Uninstall boost from MacPort then re-install it with universal variant.
%% sudo port uninstall boost
%% sudo port install boost +universal
It is possible that the name of the library is not exactly boost_system but maybe boost_system-mt (the -mt is because boost was compiled with thread safety) or even some other suffix.
To be sure, you can look up the name in /opt/local/lib:
find /opt/local/lib -name "libboost_system*"

Resources