#include未找到

发布于 2024-08-15 13:10:12 字数 490 浏览 3 评论 0原文

我已经从源代码编译了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由范儿 2024-08-22 13:10:12

希望这些目录出现在您的/etc/paths 文件中。该文件列出了 shell 搜索可执行文件的目录。

尝试:

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

您可能需要将 /usr/local/lib 添加到您的 DYLD_LIBRARY_PATH 以确保您的可执行文件运行:(

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

假设您的 DYLD_LIBRARY_PATH 变量不没有 /usr/local/lib,并且它一开始就不是空的,如果它是空的,则应该 export DYLD_LIBRARY_PATH=/usr/local/lib

编辑:好的,根据您的评论,看起来应该可行:

export CMAKE_INCLUDE_PATH=/usr/local/include
export CMAKE_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 放在您的桌面文件夹中。然后打开终端(应用程序 -> 实用程序 -> 终端)并键入:

mv ~/Desktop/a.plist ~/.MacOSX/environment.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:

$ 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文