创建静态库并使用prefake连接到它 [英] Creating static library and linking to it with premake

查看:250
本文介绍了创建静态库并使用prefake连接到它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试学习如何使用premake 4,以便将其应用于OpenGL sdk 。我目前正试图做一个Visual Studio 2010解决方案构建2个项目,一个是静态库,另一个包含一个主要的源文件,与主要方法。

I am currently trying to learn how to use premake 4 in order to apply it to the OpenGL sdk. I am currently trying to make a Visual Studio 2010 solution that constructs 2 projects, one being a static library, the other contains a single main source file, with the main method.

这个项目非常简单,仅用于学习预习的目的。在静态库项目中,名为Test,我有2个文件,Test.h和Test.cpp。 Test.h包含方法print()的原型。 print()只是打印一行到控制台。使用premake,我将静态库链接到Main项目,并且在main.cpp中包含了Test.h文件。我的问题是这样:在VS2010我得到这个错误时,我试图构建:

This project is extremely simple, and is solely for the purpose of learning premake. In the static library project, named Test, I have 2 files, Test.h and Test.cpp. Test.h contains the prototype for the method print(). print() simply prints a line to the console. Using premake, I linked the static library to the Main project, and in main.cpp I have included the Test.h file. My problem is this: in VS2010 I get this error when I attempt to build:


1>main.obj : error LNK2019: unresolved external symbol "void __cdecl print(void)" (? print@@YAXXZ) referenced in function _main  
1>.\Main.exe : fatal error LNK1120: 1 unresolved externals

这是我的代码在4个文件,preake4.lua:

Here is my code in the 4 files, the premake4.lua:

solution "HelloWorld"
    configurations {"Debug", "Release"}
project "Main"
    kind "ConsoleApp"
    language "C++"
    files{
        "main.cpp"

    }
    configuration "Debug"
        defines { "DEBUG" }
        flags { "Symbols" }

    configuration "Release"
        defines { "NDEBUG" }
        flags { "Optimize" } 
    links {"Test"}
project "Test"
    kind "StaticLib"
    language "C++"
    files{
        "test.h",
        "test.cpp"

    }

Test.cpp:

#include <iostream>

void print(){
    std::cout << "HELLO" << std::endl;
}

Test.h:

void print();

Main.cpp:

#include <conio.h>
#include "test.h"
int main(){
    print();
    getch();
    return 0;
}   



如果你想知道为什么有一个getch控制台立即关闭一旦它到达返回0,所以我使用getch()来解决这个问题,这迫使窗口等待,直到用户按下另一个键。任何关于这个问题的建议将是美好的,因为我只是不知道什么问题是。如果它是简单的,请不要阉割我,我对预制和静态库非常少的经验,这就是为什么我想学习他们。

If you are wondering why there is a getch() there, on my computer the console immediately closes once it reaches return 0, so I use getch() to combat that issue, which forces the window to wait until the user has pressed another key. Any advice on this issue would be wonderful, because I simply am not sure what the problem is. If it is something simple please dont castrate me on it, I have very little experience with premake and static libraries, which is why I am trying to learn them.

推荐答案

links {"Test"}

Lua不是Python。空格与Lua无关,就像空格对C ++无关紧要。因此,您的链接语句仅适用于发布配置。如果你想把它应用到项目作为一个整体,它需要在配置语句之前,就像你的 kind files 和其他命令。

Lua is not Python. Whitespace is irrelevant to Lua, just like whitespace doesn't matter to C++. So your links statement only applies to the "Release" configuration. If you want it to apply to the project as a whole, it needs to go before the configuration statement, just like your kind, files, and other commands.

Premake4以这种方式工作,只用于Release构建(或Debug或其他)。实际上,您可以在配置下放置几乎任何 项目因此,您可以具有仅在调试版本中使用的特定文件,或任何其他文件。

Premake4 works this way so that you could have certain libraries that are only used in a "Release" build (or Debug or whatever). Indeed, you can put almost any project command under a configuration. So you can have specific files that are used only in a debug build, or whatever.

这篇关于创建静态库并使用prefake连接到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆