makefile - 使用Premake链接到外部库

标签 makefile premake

我无法使用premake获得与主程序的外部库链接。例如,我已将问题简化为以下示例:

./_external/ext.cpp

#include "ext.h"
int foo()
{
    return 4;
}

./_external/ext.h
#pragma once
int foo();

./main.cpp
#include "stdio.h"
#include "_external/ext.h"

int main()
{
    printf("%d", foo());
    return 0;
}

./premake4.lua
solution "Test"
    configurations { "Release", "Debug" }

project "TestMain"
    language "C++"
    kind "ConsoleApp"

    files "main.cpp"

    links
    {
        "_external/libfoo.a"
    }

我在Cygwin环境下创建GNU makefile:
$ ./premake4.exe gmake
Building configurations...
Running action 'gmake'...
Generating Makefile...
Generating TestMain.make...
Done.

并且在执行时收到以下错误:
$ make
==== Building TestMain (release) ====
Linking TestMain
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lD:/test/_external/libfoo.a
collect2: ld returned 1 exit status
TestMain.make:93: recipe for target `TestMain.exe' failed
make[1]: *** [TestMain.exe] Error 1
Makefile:16: recipe for target `TestMain' failed
make: *** [TestMain] Error 2

我发现的唯一解决方法是使用“ linkoptions ”代替“ links ”来摆脱“-l”,但对我而言,它更像是一种hack,而不是解决方案。

最佳答案

您做对了,但是Premake弄错了。 Premake的makefile生成器中存在一个错误,该错误导致事物无法正确链接。现在,它已在stable(将成为版本4.4)和dev(将成为5.0)存储库中修复。

很高兴将其修复-希望能有所帮助。

关于makefile - 使用Premake链接到外部库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10482997/

相关文章:

opengl - 无法让预制作工作 - 过度演示

c++ - 用于在 header 更改时重新编译的简单 C 项目的示例 makefile

java - makefile 错误

c - 已安装检查 c 但未找到 "check.h"

根据 Makefile 的说明选择不同的头文件

premake - 多平台预制脚本

resources - 在 premake 中处理非源代码文件

python - 我可以为我的 Python 扩展模块(用 C++ 编写)使用替代构建系统吗?

c++ - 创建静态库并使用 premake 链接到它

c - Makefile,更好理解规则