我目前正試圖學習如何使用premake 4以將其應用於OpenGL sdk。我目前正在嘗試製作一個Visual Studio 2010解決方案,該解決方案構建2個項目,一個是靜態庫,另一個包含一個主要源文件和主要方法。創建靜態庫並通過預製鏈接到它
這個項目非常簡單,只是爲了學習premake的目的。在名爲Test的靜態庫項目中,我有2個文件,Test.h和Test.cpp。 Test.h包含print()方法的原型。 print()只是打印一行到控制檯。使用premake,我將靜態庫鏈接到Main項目,並在main.cpp中包含了Test.h文件。我的問題是這樣的:
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl print(void)" (? [email protected]@YAXXZ) referenced in function _main 1>.\Main.exe : fatal error LNK1120: 1 unresolved externals
這裏是我的代碼在4個文件中,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的:在VS2010當我嘗試建立我得到這個錯誤
#include <iostream>
void print(){
std::cout << "HELLO" << std::endl;
}
Test.h:
void print();
MAIN.C PP:
#include <conio.h>
#include "test.h"
int main(){
print();
getch();
return 0;
}
如果你想知道爲什麼有一個殘培()那裏,在我的電腦上的控制檯立即關閉,一旦它到達返回0,所以我使用的getch(),以應對這一問題,這迫使窗口等待用戶按下另一個鍵。任何關於這個問題的建議都會很棒,因爲我不確定問題是什麼。如果它是簡單的東西,請不要閹割我,我對premake和靜態庫很少有經驗,這就是爲什麼我試圖學習它們。
這就是問題所在,但是現在我遇到了一個問題,當我嘗試運行構建時,彈出窗口中顯示:無法啓動程序:'file_location \。\ Test.lib'指定的文件處於無法識別或不受支持的狀態二進制格式。任何幫助? PS。我更改的是將Links {「Test」}移至語言正下方。 – user1032369
@ user1032369:這是因爲您正在嘗試運行*庫*,而不是可執行文件。更改當前的「啓動項目」。 –
所以我只能通過點擊可執行文件來運行預製程序,我不能直接從VS運行它。 – user1032369