【发布时间】:2016-02-27 11:25:24
【问题描述】:
我的 C++ 项目有问题,我在 Windows 机器上的 Visual Studio 2013 中成功创建并编译了该项目。目前我正在将源代码迁移到 Unix 平台(我的问题已在 Mac 和 CentOs 上得到确认)。我的项目依赖于 OpenMP(多线程支持)库。因此 Apples LLVM 编译器(6.0 版)不充分支持 OpenMp 我决定使用 g++-5 编译我的项目。
在从 windows 编译器迁移到 GNU 的 gcc/g++ (Homebrew gcc 5.2.0) 时处理了一些语法错误后,我在链接过程中遇到了以下问题:
链接器找不到我的体系结构的符号,并列出了我创建和包含的几乎所有类/对象 - 奇怪的是,它没有列出我的每个类/对象。
我正在用这个命令编译:
g++-5 myProject.cpp -o myProject -fopenmp -std=c++11 -L/usr/local/lib -I/usr/local/Cellar/libiomp/20150701/include/libiomp -Wall
我是否在编译器调用中遗漏了一些愚蠢的东西?我的链接器问题的原因是什么? 如上所述,Mac 和 CentO 也会出现同样的问题。
EDIT (根据一些 cmets): 根据this question,我已经激活了所有警告标志,编译器对我的代码非常满意。但是链接器是这样说的:
Undefined symbols for architecture x86_64:
"FileHelper::createFileName[abi:cxx11](char const*, char const*)", referenced from:
_main in ccZAvFqT.o
"Statistics::writeStats(char const*)", referenced from:
_main in ccZAvFqT.o
"Statistics::newSimulationRun()", referenced from:
_main in ccZAvFqT.o
"Statistics::newSimulationIteration()", referenced from:
_main in ccZAvFqT.o
"Statistics::Instance()", referenced from:
_main in ccZAvFqT.o
"Statistics::writeAvg()", referenced from:
_main in ccZAvFqT.o
"Statistics::~Statistics()", referenced from:
_main in ccZAvFqT.o
"GraphHelper::Graph::writeGraph(std::vector<IPeer*, std::allocator<IPeer*> >*, std::vector<Connection*, std::allocator<Connection*> >*)", referenced from:
[...] and so on and so on...
【问题讨论】:
-
我没有看到找到 OpenMP 库的路径,例如
-L/usr/local/Cellar...。 -
是
myProject.cpp你唯一的源文件吗? -
@RSahu
-fopenmp在 mac 上发挥了神奇的作用。或-libgomp在 CentO 上。 -
@M.M
myProject.cpp是我的主文件。它包括很多其他人。 -
@Marschal 所以你实际上并没有编译其他
.cpp文件 - 这可以解释你的问题
标签: c++ visual-c++ gcc g++