未找到架构 x86_64 的符号 - Cmake - Mac sierra

2024-01-12

最近我开始了一个 C++ 的新项目。问题是,当我尝试编译它时,出现链接错误。我今天花了一整天的时间尝试调试它,但我并没有真正在任何地方找到好的解决方案。如果有人能帮忙那就太好了。我使用的是 Mac Sierra。

parsing/methylation.h

#ifndef EPIRL_METHYLATION_H
#define EPIRL_METHYLATION_H

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>

using namespace std;

namespace methylation {
    struct MethLine {
        string chr;
        int coord;
        char strand;
        int methylated;
        int un_methylated;
        string context;
        string tag;
    };

    string calculateMethylationByContext(
            MethLine m_input[], int length,
            int window_start, int window_end, int threshold);

    void calculateMethylation(
        const istream &methylation_stream,
        const istream &coordinate_stream,
        const ostream &output_stream
    );
}

#endif //EPIRL_METHYLATION_H

parsing/methylation.cpp

#include "methylation.h"

namespace methylation {
    string calculateMethylationByContext(
            MethLine m_input[], int length,
            int window_start, int window_end, int threshold) {
// rest of the code ...
    }
}

main.cpp

#include <iostream>
#include <fstream>
#include "parsing/methylation.h"

using namespace std;

int main(int argc, char **argv) {
    if (argc != 4) {
        cout << "Invalid number of arguments..." << endl;
        return 1;
    }

    char *methylation_file = argv[1];
    char *coordinate_file = argv[2];
    char *output_file = argv[3];

    ifstream methylation_file_stream(methylation_file, ios::binary);
    ifstream coordinate_file_stream(coordinate_file, ios::binary);
    ofstream output_file_stream(output_file, ios::binary);

    methylation::calculateMethylation(methylation_file_stream,
                         coordinate_file_stream, output_file_stream);
    methylation_file_stream.close();
    coordinate_file_stream.close();
    output_file_stream.close();

    return 0;
}

我使用 CLion 进行编码。当我尝试构建它时,我的 cmake 命令工作正常,但是当我单击“make”时,出现以下错误:

Undefined symbols for architecture x86_64:
  "methylation::calculateMethylation(std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> > const&)", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [src] Error 1
make[2]: *** [CMakeFiles/src.dir/all] Error 2
make[1]: *** [CMakeFiles/src.dir/rule] Error 2
make: *** [src] Error 2

my CMakeLists.txt文件如下所示:

cmake_minimum_required(VERSION 3.6)
project(src)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES
    parsing/methylation.cpp
    parsing/methylation.h
    main.cpp)

add_executable(src ${SOURCE_FILES})

当我运行 cmake 命令时,我的输出是这样的:

-- The C compiler identification is AppleClang 8.0.0.8000042
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/sztankatt/Documents/University/PartIII/Project/epiRL/src

Your CMakeLists.txt很好。

正如 @thomas-matthews @tsyvarev @nos 在他们的评论中指出的那样,您的示例代码缺少以下定义/实现methylation::calculateMethylation()。您所看到的是在这种情况下 Apple/clang 的预期失败。

❯ make
[ 33%] Building CXX object CMakeFiles/src.dir/parsing/methylation.cpp.o
/Users/nega/foo/parsing/methylation.cpp:8:5: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
1 warning generated.
[ 66%] Building CXX object CMakeFiles/src.dir/main.cpp.o
[100%] Linking CXX executable src
Undefined symbols for architecture x86_64:
  "methylation::calculateMethylation(std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> > const&)", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src] Error 1
make[1]: *** [CMakeFiles/src.dir/all] Error 2
make: *** [all] Error 2

添加一个虚拟实现,或者注释掉您的调用main.cpp, 会允许make才能成功完成。

假设你有一个正确的实现

假设您确实有一个实现methylation::calculateMethylation()在您的代码中(也许在另一个文件中)。调试 CMake 生成的 Makefile 中的构建错误的第一步是使用 make 变量运行VERBOSE设置为真值,即:make VERBOSE=1.

❯ make VERBOSE=1
/usr/local/Cellar/cmake/3.7.0/bin/cmake -H/Users/nega/foo -B/Users/nega/foo/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.7.0/bin/cmake -E cmake_progress_start /Users/nega/foo/build/CMakeFiles /Users/nega/foo/build/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/src.dir/build.make CMakeFiles/src.dir/depend
cd /Users/nega/foo/build && /usr/local/Cellar/cmake/3.7.0/bin/cmake -E cmake_depends "Unix Makefiles" /Users/nega/foo /Users/nega/foo /Users/nega/foo/build /Users/nega/foo/build /Users/nega/foo/build/CMakeFiles/src.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/src.dir/build.make CMakeFiles/src.dir/build
[ 33%] Building CXX object CMakeFiles/src.dir/parsing/methylation.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++     -std=gnu++11 -o CMakeFiles/src.dir/parsing/methylation.cpp.o -c /Users/nega/foo/parsing/methylation.cpp
/Users/nega/foo/parsing/methylation.cpp:8:5: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
1 warning generated.
[ 66%] Building CXX object CMakeFiles/src.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++     -std=gnu++11 -o CMakeFiles/src.dir/main.cpp.o -c /Users/nega/foo/main.cpp
[100%] Linking CXX executable src
/usr/local/Cellar/cmake/3.7.0/bin/cmake -E cmake_link_script CMakeFiles/src.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++    -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/src.dir/parsing/methylation.cpp.o CMakeFiles/src.dir/main.cpp.o  -o src 
Undefined symbols for architecture x86_64:
  "methylation::calculateMethylation(std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> > const&)", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src] Error 1
make[1]: *** [CMakeFiles/src.dir/all] Error 2
make: *** [all] Error 2

现在您可以查看链接步骤,看看是否缺少项目;也许是一个库,或者是一个目标文件。如果是这样,现在您知道要返回并将其添加到您的CMakeLists.txt

Summary

使用 CMake 生成的 Makefile 调试意外构建失败的第一步是运行:

❯ make VERBOSE=1

这将使您深入了解 CMake 在幕后所做的事情。

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

未找到架构 x86_64 的符号 - Cmake - Mac sierra 的相关文章

随机推荐

  • 单个实体中的实体框架 1 到 0..1 关系

    Scenario 我有一个场景 在单个实体中为数据库中的两个表定义了 1 对 1 关系 我通过使用以下映射来做到这一点 为了保护无辜者 名称已更改 modelBuilder Entity
  • Symfony2 DoctrineExtensions preSoftDelete 事件调用

    我在为 Symfony2 实现 L3pp4ard DoctrineExtensions Bundle 中的 preSoftDelete 事件时遇到问题 softDelete 函数工作得很好 但我想在deletedAt 日期时间 旁边添加一个
  • 如何使用已排序的键列表对 OrderedDict 进行排序?

    假设我有一个collections OrderedDict对象及其重新排列的键列表 ordereddict collections OrderedDict key 78 value key 40 value key 96 value key
  • 我可以使用 Perl 正则表达式来匹配平衡文本吗?

    我想在 Perl 中匹配括号等中包含的文本 我怎样才能做到这一点 这是来自官方常见问题解答 http faq perl org We re 将 perlfaq 导入 Stack Overflow https meta stackexchan
  • print() / println() 执行速度慢吗?

    我有一个有几千行的应用程序 在该代码中有很多 println 命令 这会减慢应用程序的速度吗 它显然是在模拟器中执行的 但是当您从应用程序商店 TestFlight 存档 提交和下载应用程序时会发生什么 这段代码仍然是 活动的 吗 被 注释
  • 对于访问创建它的脚本的每个用户来说,mysql临时表是唯一的...?

    当用户在特定日期之间搜索免费酒店时 在寻找一种临时保存搜索结果的方法时 我遇到了临时表 但某些问题即使在 mysql 手册中也没有得到解答 比如 临时表对于执行脚本的每个用户来说都是唯一的吗 或者当两个不同的用户同时运行脚本时它会被覆盖 桌
  • 将 Excel 文件从压缩文件夹读入 R 数据帧

    我有一个 Excel 文件 xls 扩展名 位于一个压缩文件夹内 我想将其作为数据帧读取到 R 中 我加载了 gdata 库 并将工作目录设置为包含压缩文件夹的文件夹 当我输入以下语法时 data frame1 lt read xls un
  • Azure Devops YAML 管道 - 如何重复任务

    在我的 YAML 管道中 我有一个部署作业 stage deployment to development jobs deployment deployment to development displayName Deploy to De
  • 来自不同插件的重复控制器名称

    我有一个关于 Cakephp2 3 的文件加载系统的问题 我有两个插件 让我们称它们为 联系人 和 经理 加载如下 CakePlugin load Contacts CakePlugin load Managers 它们每个都有一个名为 D
  • DBCP 连接池登录超时

    根据DBCP文件 http commons apache org dbcp apidocs org apache commons dbcp BasicDataSource html setLoginTimeout 28int 29 Basi
  • 如何将包含连字符的键的对象解构为变量? [复制]

    这个问题在这里已经有答案了 如何从键包含连字符的对象解构属性 Eg accept ranges bytes cache control public max age 0 content length 1174 content type ap
  • 为 Chrome 扩展注入 CSS

    我对 Chrome 扩展开发还很陌生 我知道可以注入CSS 但是是否可以为特定的 URL 注入它 例如 每当我访问 google com 时 CSS 就会被注入 谢谢您的帮助 那么 您有 2 个选择 编程注入和内容脚本 这些名字可能听起来非
  • 将 csv 文件导入 java swing 表

    我有纽约证券交易所所有股票报价的 csv 文件 第一列是符号第二列是公司名称 我有一个使用 java swing 库在 netbeans 中制作的搜索框和表格 现在 当我在框中输入名称时 它会返回正确的行数 例如 如果我搜索 GOOG 它只
  • 根据调整窗口大小的动态高度 div

    HTML div class header Header div div class body table class body table tr td Cell td td Cell td td Cell td tr tr td Cell
  • 如何在for循环中声明变量? (IDL)

    例如 我的文件以00 dat 01 dat 02 dat 每个文件包含多个列 我使用READCOL将它们读入变量 for i 0 n 1 do begin readcol string i F I02 dat F D D a0 b0 rea
  • postgresql中如何计算空值?

    select distinct column from table output column 1 0 0 2 null 3 1 0 但是当我尝试计算空值时 select count column from train where colu
  • 直接访问子类中自动合成的实例变量?

    为了提高效率 我想访问与子类中的属性关联的成员变量 如果我有一个声明如下的财产 interface Mumbo NSObject property nonatomic GLKVector3 position end 在 Mumbo 的实现中
  • 使用 Win32 API 连接字符串

    使用 Win32 连接字符串的最佳方法是什么 如果理解正确 正常的 C 方法是使用strcat 但由于 Win32 现在处理 Unicode 字符串 又名LPWSTR 我想不出办法strcat来处理这个 有这个功能吗 还是我应该自己写 ls
  • 从分页 URL 中删除“页面”

    我在更改 Wordpress 中的分页 URL 时遇到问题 我知道这个问题的通用解决方案是更改 WordPress 核心文件 但我只需要针对一个类别使用此解决方案 也许只有一个类别可以通过 htaccess 来完成 现在有这样的网址 htt
  • 未找到架构 x86_64 的符号 - Cmake - Mac sierra

    最近我开始了一个 C 的新项目 问题是 当我尝试编译它时 出现链接错误 我今天花了一整天的时间尝试调试它 但我并没有真正在任何地方找到好的解决方案 如果有人能帮忙那就太好了 我使用的是 Mac Sierra parsing methylat