'Clion can't find a library installed using homebrew

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?



Solution 1:[1]

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gyj