我无法使用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)存储库中修复。
很高兴将其修复-希望能有所帮助。