#include未找到
我已经从源代码编译了 FreeImage 并安装了它。
当我运行 sudo make install 时,会在我的系统上安装以下文件
/usr/local/include/FreeImage.h
/usr/local/lib/libfreeimage-3.10.0.dylib
/usr/local/lib/libfreeimage.a
但是,在我的 C++ 程序中,当我执行此操作时,它会显示错误文件未找到:
#include <FreeImage.h>
我已尝试将其添加到我的系统路径文件:
sudo vi /etc/paths
#FreeImage
/usr/local/include
/usr/local/lib
但 C++ 仍然无法在 Xcode 或 gcc 中找到我的 #include
。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不希望这些目录出现在您的
/etc/paths
文件中。该文件列出了 shell 搜索可执行文件的目录。尝试:
您可能需要将
/usr/local/lib
添加到您的DYLD_LIBRARY_PATH
以确保您的可执行文件运行:(假设您的
DYLD_LIBRARY_PATH
变量不没有/usr/local/lib
,并且它一开始就不是空的,如果它是空的,则应该export DYLD_LIBRARY_PATH=/usr/local/lib
)编辑:好的,根据您的评论,看起来应该可行:
请参阅 如果系统上存在该包,但 cmake 找不到该包该怎么办? 了解更多信息。
由于您使用的是 GUI 版本的 Cmake,因此您应该执行以下操作:
打开“属性列表编辑器”,单击“添加子项”。对于“New item”,输入
CMAKE_INCLUDE_PATH
,对于 Type,将其保留为“String”,对于 Value,输入/usr/local/include
。然后,再次单击“添加项目”,并在“新项目”中输入CMAKE_LIBRARY_PATH
,将类型保留为“String”,在“Value”中输入/usr/local/lib
代码>.然后保存(文件 -> 另存为)到文件。我建议将文件名a.plist
放在您的桌面文件夹中。然后打开终端(应用程序 -> 实用程序 -> 终端)并键入:之后,退出 Xcode 和 Cmake gui,然后重新启动。那应该有效。请参阅 此了解技术细节,以及此了解更多。
You don't want those directories in your
/etc/paths
file. That files lists the directories where the shell searches for executables.Try:
You might need to add
/usr/local/lib
to yourDYLD_LIBRARY_PATH
to make sure your executable runs:(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 doexport DYLD_LIBRARY_PATH=/usr/local/lib
instead.)Edit: OK, based on your comments, looks like this should work:
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 enterCMAKE_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 filenamea.plist
in your Desktop folder. Then open a terminal (Appilcations -> Utilities -> Terminal) and type:After that, quit Xcode and Cmake gui, and restart. That should work. See this for technical details, and this for more.