2

I have compiled FreeImage from source and installed it.

When I run sudo make install in installs the following files on my system

/usr/local/include/FreeImage.h
/usr/local/lib/libfreeimage-3.10.0.dylib
/usr/local/lib/libfreeimage.a

However in my C++ program it says error file not found when I do this:

#include <FreeImage.h> 

I have tried adding this to my system path file:

sudo vi /etc/paths

#FreeImage
/usr/local/include
/usr/local/lib

But C++ still cannot find my #include inside Xcode or with gcc.

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Brock Woolf
  • 46,656
  • 50
  • 121
  • 144

1 Answers1

3

You don't want those directories in your /etc/paths file. That files lists the directories where the shell searches for executables.

Try:

$ CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" make
$ sudo make install

You might need to add /usr/local/lib to your DYLD_LIBRARY_PATH to make sure your executable runs:

$ export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH

(Assuming your DYLD_LIBRARY_PATH variable doesn't have /usr/local/lib, and that it's not empty to begin with. If it is empty, you should do export DYLD_LIBRARY_PATH=/usr/local/lib instead.)

Edit: OK, based on your comments, looks like this should work:

export CMAKE_INCLUDE_PATH=/usr/local/include
export CMAKE_LIBRARY_PATH=/usr/local/lib

See What to do if cmake doesn't find the package although it exists on the system? for more.

Since you're using a GUI version of Cmake, you should do this:

Open "property list editor", click "add child". For "New item", enter CMAKE_INCLUDE_PATH, for Type, leave it as "String", for Value, enter /usr/local/include. Then, click "add item" again, and enter CMAKE_LIBRARY_PATH for "New item", leave type as "String", and for "Value", enter /usr/local/lib. Then save (File -> Save as) to a file. I suggest filename a.plist in your Desktop folder. Then open a terminal (Appilcations -> Utilities -> Terminal) and type:

mv ~/Desktop/a.plist ~/.MacOSX/environment.plist

After that, quit Xcode and Cmake gui, and restart. That should work. See this for technical details, and this for more.

Alok Singhal
  • 93,253
  • 21
  • 125
  • 158
  • The problem is not that Xcode cannot see the library file, it's that it cannot see the header file. Which file on the system does Xcode consult to see where a `#include <>` exists? – Brock Woolf Dec 14 '09 at 04:18
  • @Alok thanks for your suggestions. I have added the CFLAGS and LDFLAGS to the makefile and I'm recompiling... fingers crossed. – Brock Woolf Dec 14 '09 at 04:27
  • It made no difference unfortunately. I think ill try hardcoding the paths for now – Brock Woolf Dec 14 '09 at 04:31
  • In Xcode, in Project -> Edit Project Settings, in "Build" tab, you can change "Header Search Paths" and "Library Search Paths" in the "Search Paths" option. Do it for "All Configurations". – Alok Singhal Dec 14 '09 at 04:35
  • Okay. The problem is that I'm using CMake to build Gazebo, and CMake runs a script internally which uses: `#include ` - Is there not some system wide variable which gcc consults? – Brock Woolf Dec 14 '09 at 04:38
  • If this is the same question as http://stackoverflow.com/questions/1891836/compiled-freeimage-from-source-include-freeimage-h-not-found, try adding the "-I..." to COMPILERFLAGS variable. – Alok Singhal Dec 14 '09 at 04:41
  • Thanks for your help. But you say "this should work" where exactly do I use those two commands? – Brock Woolf Dec 14 '09 at 07:24
  • I am using the GUI version of CMake....CMake builds the Xcode project files for Gazebo. – Brock Woolf Dec 14 '09 at 07:35
  • Thanks for your help Alok. I've tried the plist file, then restarting and some variations on the things you stated. There's a lot of good things in there, I just think that Apple have made some serious unix changes in 10.6 because it's still not working for me. Anyways I'd double upvote your answer if I could. The tick will have to do. I think this might at least help some other people. Thanks again. – Brock Woolf Dec 14 '09 at 09:34
  • You could try running commandline version of cmake with the above environment variables set. I don't use cmake, so I am not sure if the GUI allows you to add include and link paths before running the make process. I am not sure if the tick helps because you haven't solved your problem and it might prevent others from replying to this question. – Alok Singhal Dec 15 '09 at 03:52