我无法使用premake获得与主程序的外部库链接。例如,我已将问题简化为此示例:
./_外部/ ext.cpp
#include "ext.h"
int foo()
{
return 4;
}
./_外部/ 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 ”而不是“链接”来摆脱“-l”但对我来说它更像是黑客攻击而非解决方案。