问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/1898837/include-freeimage-h-not-found