我正在尝试使用premake,但是我无法使我的测试项目正确地与其链接。如果我手动链接它,虽然可以正常工作。

我在带有clang 3.4的OS X 10.9上使用了premake 4.3(也用premake 4.4进行了测试)。

通过“premake4 gmake”创建makefile并尝试对其进行编译后,出现如下错误:

Linking subproject
ld: internal error: atom not found in symbolIndex(__ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [libsubproject.dylib] Error 1
make: *** [subproject] Error 2

我非常简单的项目设置:
project/
    src/
        test.cpp
    subproject/
        include/
            Library.hpp
        source/
            Library.cpp
    premake4.lua

premake4.lua
solution "testa"
    configurations {"debug"}
    language "C++"

    includedirs {"subproject/include"}

    project "subproject"
        kind "SharedLib"
        files {"subproject/source/*.cpp"}

    project "main"
        kind "ConsoleApp"
        files {"src/*.cpp"}

        links {"subproject"}

src / test.cpp
#include <iostream>
#include <Library.hpp>

using namespace std;

int main() {
    cout << "Hello, World!" << endl;

    Library lib(13, 3);

    lib.do_stuff(7);

    return 0;
}

子项目/include/Library.hpp
#ifndef __LIBRARY_HPP__
#define __LIBRARY_HPP__

#include <iostream>

using namespace std;

class Library {
public:
    Library(int, int);
    void do_stuff(int) const;

private:
    int x;
    int y;

};

#endif

子项目/来源/Library.cpp
#include <Library.hpp>

Library::Library(int x, int y) {
    this->x = x;
    this->y = y;
}

void Library::do_stuff(int z) const {
    cout << "X: " << x << "Y: " << y << "Z: " << z << endl;
}

感谢您的时间。

最佳答案

这是一个已知的预制错误。已经报告并修复了该问题,但是该程序的修复版本尚未发布。参见讨论here

此错误是由-Wl,-x链接器标志引起的,该标志在默认情况下会预先添加到project.make生成文件中。到目前为止,有两种可能的解决方案,下载带有修复程序的更新的premake源,进行编译并安装新版本,或者在每次运行premake之后手动更改生成的LDFLAGSproject.make的值。

我也尝试了他们在上面将premake.tools.gcc.ldflags.flags._Symbols设置为nil的链接中给出的建议,但这对我的系统没有影响。

关于c++ - 无法将我的解决方案中的其他项目与premake链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22689492/

10-11 18:30