mihaipopescu
mihaipopescu

Reputation: 967

Linking to an external library with Premake

I can't get an external library link with the main program using premake. For instance I've simplified the problem to this example:

./_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"
    }

I create the GNU makefiles under Cygwin environment:

$ ./premake4.exe gmake
Building configurations...
Running action 'gmake'...
Generating Makefile...
Generating TestMain.make...
Done.

and I get the following error when I make:

$ 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

The only workaround I found is to use "linkoptions" instead of "links" to get rid of the "-l" but for me it's more like a hack than a solution.

Upvotes: 3

Views: 4045

Answers (1)

J. Perkins
J. Perkins

Reputation: 4276

You are doing it right, but Premake is getting it wrong. There was a bug in Premake's makefile generator that prevented things from linking properly. It is now fixed in both the stable (will become version 4.4) and dev (will become 5.0) repositories.

Nice to get that fixed—hope it helps.

Upvotes: 1

Related Questions