将 Intel 编译器变量包含到 CMake makefile 中
我正在使用 CMake 2.8.6 和最新的Intel C++ 编译器来编写针对 Linux、MacOSX 和 Windows 编译的程序。对于开发,我在 Linux 和 MacOSX 上使用带有 CDT 的 Eclipse。
直到最近,我还使用 CMake 创建从控制台运行的常用 Makefile。为了拥有一个工作环境,英特尔编译器附带了一个名为 iccvars.sh
的 shell 脚本,可以对其进行源码
设置所有必需的包含路径和库路径。
现在我决定给 Eclipse-CDT 构建系统一个机会,并使用 CMake 的“Eclipse CDT4 - Unix Makefiles”生成器来创建 Eclipse 项目文件。在 Linux 下一切正常,但在 OSX 下,Eclipse 不知道环境变量,因此像 DYLD_LIBRARY_PATH 这样的路径丢失,编译停止,因为找不到库。
更新
让我更详细地解释一下我所做的事情。我在
cmake -G "Eclipse CDT4 - Unix Makefiles" path/to/src
执行 source iccvars.sh
的终端内运行,并且所有环境变量均已正确设置。如果我在那里创建了一个普通的 Makefile 并运行 make
,编译就会成功。这是因为 DYLIB_LIBRARY_PATH
(在 Linux 中 LD_LIBRARY_PATH
)设置正确,我不必给出 -L/path/to/libs
作为编译器的选项。
但相反,我启动 Eclipse 并导入创建的 .project
,效果很好。问题是 Eclipse 不知道我在控制台中的环境,因此无法找到所需的库。一种解决方案是在 CMakeLists.txt
中使用 find_library
并找到每个所需的库,因为完整路径应包含在创建的 Makefile 中。相反,我想知道是否...
问题:有没有办法将 iccvars.sh
源到我的 CMakeLists.txt 中,以便即使我不在通常的终端环境中,路径也可用吗?还有其他的可能性吗?
请注意,我知道您可以在 OSX 下为 GUI 程序设置环境变量。您所要做的就是在您家中的 ~/.MacOSX
下创建一个文件 environment.plist
。在这个 xml 文件中,您放置了 GUI 程序应具有的所有变量。这对于其他应用程序来说效果很好,但尤其是 Eclipse-builder 似乎忽略了这一点。
I'm using CMake 2.8.6 and the latest Intel C++ Compiler for a program which is compiled for Linux, MacOSX and Windows. For the development I'm using Eclipse with CDT on Linux and MacOSX.
Until recently I used CMake to create usual Makefiles which I ran from the console. To have a working environment, the Intel compiler comes with a shell-script called iccvars.sh
which can be source
d to set all required include- and library-paths.
Now I decided to give the Eclipse-CDT build-system a chance and used the "Eclipse CDT4 - Unix Makefiles" generator of CMake to create an Eclipse project file. Everything works fine under Linux, but under OSX, Eclipse does not know about the environment variables and therefore paths like DYLD_LIBRARY_PATH
are missing and the compilation stops because libraries are not found.
Update
Let me explain in more detail what I do. I'm running
cmake -G "Eclipse CDT4 - Unix Makefiles" path/to/src
from within the terminal where source iccvars.sh
was executed and all environment-variables are set correctly. If I would have created a normal Makefile there and would run make
, the compilation would succeed. This is because of the DYLIB_LIBRARY_PATH
(in Linux LD_LIBRARY_PATH
) is set correctly and I do not have to give -L/path/to/libs
as option to the compiler.
But instead, I start Eclipse and import the created .project
which works fine. The problem is that Eclipse do not know about my environment in the console and therefore cannot find the required libraries. One solution would be to use find_library
inside CMakeLists.txt
and locate every required library because then the full path should be included in the created Makefiles. Instead, I was wondering whether...
Question: Is there a way to source the iccvars.sh
into my CMakeLists.txt so that the paths are available even when I'm not in my usual terminal-environment? Are there other possibilities?
Please note, that I know you can set environment variables for GUI-programs under OSX. What you have to do is to create a file environment.plist
in your home under ~/.MacOSX
. In this xml-file you put all your variables a GUI program should have. This works fine for other applications, but especially the Eclipse-builder seems to ignore this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论