C++ 链接器错误:仅在优化构建上未定义引用

2023-11-21

我收到未定义的引用链接器错误only当链接优化的对象文件时,not链接未优化的目标文件时。我不明白问题是什么或可能是什么。

这是我未优化的构建:



Building file: ../COMPASS.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"COMPASS.d" -MT"COMPASS.d" -o"COMPASS.o" "../COMPASS.cpp"
Finished building: ../COMPASS.cpp

Building file: ../PSA.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"PSA.d" -MT"PSA.d" -o"PSA.o" "../PSA.cpp"
Finished building: ../PSA.cpp

Building file: ../SAR.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"SAR.d" -MT"SAR.d" -o"SAR.o" "../SAR.cpp"
Finished building: ../SAR.cpp

Building file: ../constraints.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"constraints.d" -MT"constraints.d" -o"constraints.o" "../constraints.cpp"
Finished building: ../constraints.cpp

Building file: ../genetic.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"genetic.d" -MT"genetic.d" -o"genetic.o" "../genetic.cpp"
Finished building: ../genetic.cpp

Building file: ../globals.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"globals.d" -MT"globals.d" -o"globals.o" "../globals.cpp"
Finished building: ../globals.cpp

Building file: ../logging.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"logging.d" -MT"logging.d" -o"logging.o" "../logging.cpp"
Finished building: ../logging.cpp

Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp

Building file: ../sampling.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"sampling.d" -MT"sampling.d" -o"sampling.o" "../sampling.cpp"
Finished building: ../sampling.cpp

Building file: ../simulation1.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"simulation1.d" -MT"simulation1.d" -o"simulation1.o" "../simulation1.cpp"
../globals.h: At global scope:
../globals.h:43: warning: inline function 'double showDecimals(const double&, const int&)' used but never defined
Finished building: ../simulation1.cpp

Building file: ../test_function.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"test_function.d" -MT"test_function.d" -o"test_function.o" "../test_function.cpp"
Finished building: ../test_function.cpp

Building target: pc2
Invoking: GCC C++ Linker
g++ -pg -fopenmp -pg -o"pc2"  ./COMPASS.o ./PSA.o ./SAR.o ./constraints.o ./genetic.o ./globals.o ./logging.o ./main.o ./sampling.o ./simulation1.o ./test_function.o   
Finished building target: pc2
  

这是我的优化构建:



Building file: ../COMPASS.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"COMPASS.d" -MT"COMPASS.d" -o"COMPASS.o" "../COMPASS.cpp"
Finished building: ../COMPASS.cpp

Building file: ../PSA.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"PSA.d" -MT"PSA.d" -o"PSA.o" "../PSA.cpp"
Finished building: ../PSA.cpp

Building file: ../SAR.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"SAR.d" -MT"SAR.d" -o"SAR.o" "../SAR.cpp"
Finished building: ../SAR.cpp

Building file: ../constraints.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"constraints.d" -MT"constraints.d" -o"constraints.o" "../constraints.cpp"
Finished building: ../constraints.cpp

Building file: ../genetic.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"genetic.d" -MT"genetic.d" -o"genetic.o" "../genetic.cpp"
Finished building: ../genetic.cpp

Building file: ../globals.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"globals.d" -MT"globals.d" -o"globals.o" "../globals.cpp"
Finished building: ../globals.cpp

Building file: ../logging.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"logging.d" -MT"logging.d" -o"logging.o" "../logging.cpp"
Finished building: ../logging.cpp

Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp

Building file: ../sampling.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"sampling.d" -MT"sampling.d" -o"sampling.o" "../sampling.cpp"
Finished building: ../sampling.cpp

Building file: ../simulation1.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"simulation1.d" -MT"simulation1.d" -o"simulation1.o" "../simulation1.cpp"
../globals.h: At global scope:
../globals.h:43: warning: inline function 'double showDecimals(const double&, const int&)' used but never defined
Finished building: ../simulation1.cpp

Building file: ../test_function.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"test_function.d" -MT"test_function.d" -o"test_function.o" "../test_function.cpp"
Finished building: ../test_function.cpp

Building target: pc2
Invoking: GCC C++ Linker
g++ -fopenmp -o"pc2"  ./COMPASS.o ./PSA.o ./SAR.o ./constraints.o ./genetic.o ./globals.o ./logging.o ./main.o ./sampling.o ./simulation1.o ./test_function.o   
./logging.o: In function `LOG_COMPASS_display_points_MATLAB(int const&, VisitedSet&)':
logging.cpp:(.text+0x686): undefined reference to `VisitedSet::getSize()'
collect2: ld returned 1 exit status
make: *** [pc2] Error 1
make: Leaving directory `/home/djunderw/ncsu/workspace/pc2/release'
  

有任何想法吗?

[修复了 showDecimals() 函数的问题]

文件 COMPASS.h 包含此类模板:

template<class T> class VisitedSet {
public:
    VisitedSet(const T& soln); 
    int getSize();
    void addSolution(const T& soln);
    void evaluate();
    void sample(const int& numNewSolutions, Constraints& space);
    void CSBiased_generateDistribution();
    void constructMPA(Constraints& space);
    vector<T> vec;
    double bestValue;
    int bestIndex;

    /* used to implement biased coordinate sampling */
    double CSBiased_coefficient;
    vector< vector<double> > lastSampledPoints;
    vector<int> lastSampledPointsIndex;
    vector< vector<double> > newSampledPoints;
    vector<int> newSampledPointsIndex;
    vector<double> CSBiased_distribution;

private:
    int iteration;
    int dimension; 
    int SAR(); // simulation allocation rule
};

COMPASS.cpp 包含以下代码:

template<class T>
int VisitedSet<T>::getSize() {
    return vec.size();
}

logging.cpp 文件包含以下代码:

#include "COMPASS.h"
void LOG_COMPASS_display_points_MATLAB(const int& iteration, VisitedSet<Policy>& visited) {
    cout << "points{"<<iteration+1<<"} = [\n"
         << visited.vec[visited.bestIndex].x[0] << "\t" <<     visited.vec[visited.bestIndex].x[1] << "\t" << visited.vec[visited.bestIndex].meanQALY() << ";" << endl;
for(int i=0; i<visited.getSize(); i++) {
    if(i != visited.bestIndex)
        cout << visited.vec[i].x[0] << "\t" << visited.vec[i].x[1] << "\t" << visited.vec[i].meanQALY() << ";" << endl;
}
cout << "];\n";
}

int VisitedSet<T>::getSize()是一个模板函数,所以它的定义应该在像COMPASS.h这样的头文件中,而不是在COMPASS.cpp中。

原因如下:http://www.parashift.com/c++-faq/templates-defn-vs-decl.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++ 链接器错误:仅在优化构建上未定义引用 的相关文章

随机推荐

  • jftfdi jffi 对我的查询字符串做了什么?

    我们在项目中使用 JavaServer Faces 2 2 Mojarra 2 2 1 我注意到一些奇怪的事情 在一个名为reporting xhtml我在哪里使用f metadata与新的f viewAction我的浏览器 本例中为 Sa
  • 如何在 shell 脚本中进行异步函数调用

    我有一组由 shell 脚本执行的curl 命令 现在我想要的是所有这些命令都必须以固 定的时间间隔执行 每个curl url 都不同 所以我想做的是异步调用 wait sec 在不同的等待时间内命令并执行不同的功能 例如 启动 5 个计时
  • C# 获取窗口句柄

    我正在尝试执行一些 P Invoke 操作 并且需要当前窗口的句柄 I found C 获取窗口句柄 但似乎只适用于 WPF 有没有类似的winForms Control Handle An IntPtr包含控件的窗口句柄 HWND
  • 将列表转换为嵌套字典

    我怎样才能转换list进入嵌套的 字典 例如 l 1 2 3 4 我想将其转换为如下所示的字典 1 2 3 4 为此 反转列表 然后开始创建空字典元素 l 1 2 3 4 d for i in reversed l d i d gt gt
  • Webpack 找不到模块“电子”

    我正在尝试开发一个基于电子 Angular2 的小应用程序本教程 看来他们的 webpack 捆绑存在一些错误 因为我无法在渲染器组件中要求 导入电子遥控器 在我的 AppComponent 中我执行以下操作 import remote f
  • 无法添加名称为“testCompile”的配置,因为该名称的配置已存在

    更新到 gradle 插件 1 1 0 时 我不断收到以下错误 Cannot add a configuration with name testCompile as a configuration with that name alrea
  • 在 Visual Studio 设计器中为控件指定双击事件

    当您双击Control在 Visual Studio 设计器中 您会自动订阅一些event并在代码隐藏文件中生成事件处理程序 双击以下控件即可订阅相应的事件 UserControl Loaded Button Click TextBox 文
  • 如何在SQL Server数据库中使用UTF-8排序规则?

    我已经将数据库从mysql迁移到SQL Server 政治 原始mysql数据库使用UTF8 现在我读了https dba stackexchange com questions 7346 sql server 2005 2008 utf
  • Eclipse Android:无法打开选定的VM调试端口(8700)[重复]

    这个问题在这里已经有答案了 可能的重复 无法打开选定的 VM 调试端口 8700 打开时我在控制台上收到此错误Eclipse 无法打开选定的 VM 调试端口 8700 请确保您没有运行 DDMS 或 eclipse 插件的另一个实例 如果它
  • 删除 R 中的大括号

    如何删除R中的大括号 例如 abcd 到 abcd 如何使用 R 中的 gsub 函数来执行此操作 如果有其他方法可用 请建议 尝试这个 gsub abcd 1 abcd Or this gsub abcd
  • 如何从 javascript 文件中提取 javascript 函数

    我需要从脚本文件中提取整个 javascript 函数 我知道该函数的名称 但我不知道该函数的内容可能是什么 该函数可以嵌入任意数量的闭包中 我需要有两个输出值 我在输入脚本中找到的命名函数的整个主体 删除了找到的命名函数的完整输入脚本 所
  • 如何确保docker的时间与主机的时间同步?

    我有在 Linode 服务器上运行的 docker 有时 我发现码头工人的时间不对 目前我已经更改了每个泊坞窗中的运行脚本以包含以下代码行 yum install y ntp service ntpd stop ntpdate pool n
  • DispatchQueue.main.asyncAfter 不准确

    我试图在延迟后调用一个函数 在 iOS10 上 我可以使用 Timer scheduledTimer 它确实会在给定的延迟后调用我的闭包 但是 在 iOS9 上 我使用 DispatchQueue main asyncAfter 它会延迟六
  • 如何在flutter中使用“DateTime”显示月份

    我有一个日历 我想在日历上方显示月份 有没有办法只显示当前月份 归功于https github com adamstyrc 对于图像 它应该看起来像这样 使用以下包作为 DateFormat https pub dev packages i
  • 我们可以说 String 是 Javascript 中的对象吗?

    当我听到字符串是 JS 中的基元时 我总是很困惑 因为每个人都知道字符串有不同的方法 例如 length indexOf search 等 let string Please locate where locate occurs let p
  • clang 和 gcc 中是否有 Visual C++ __declspec (属性声明属性)的替代方案?

    有一个 Microsoft 特定的扩展 它可以像这样定义属性 getter 和 setter declspec property cpp struct S int i void putprop int j i j int getprop r
  • xpath 和 c#

    我正在尝试创建一个通过 XML 文档进行搜索的 winform 应用程序 对于我的搜索 我需要使用 lower case xpath 函数将 xpath 条件中的 XML 属性转换为小写 这会导致与函数命名空间相关的问题 我尝试手动添加名称
  • 如何在稀疏点之间插入数据以在 R 和plotly 中绘制等高线图

    我想根据第一幅图中以下彩色点的浓度数据在 xy 平面上创建等值线图 我在每个高度都没有角点 因此我需要将浓度外推到 xy 平面的边缘 xlim c 0 335 ylim c 0 426 The plotly html file of the
  • 如何使用 Ajax 解决“NS_ERROR_ILLEGAL_VALUE”错误?

    我只是编写一个小型 Ajax 框架以实现小型项目中的可重用性 但我遇到了问题 基本上我得到一个 NS ERROR ILLEGAL VALUE 发送请求时出错 我不知道发生了什么 HTML 页面 已修剪但显示错误
  • C++ 链接器错误:仅在优化构建上未定义引用

    我收到未定义的引用链接器错误only当链接优化的对象文件时 not链接未优化的目标文件时 我不明白问题是什么或可能是什么 这是我未优化的构建 Building file COMPASS cpp Invoking GCC C Compiler