我遇到了VC++編譯器的問題。我已經安裝了Windows SDK與編譯器,庫和頭文件,並試圖編譯一個測試程序,像這樣:VC++標準庫鏈接錯誤
#include <cstdio>
int main(int argc, char* argv[]) {
printf("%s", "Hello world!");
return 0;
}
這是命令行腳本我使用編譯:
@echo off
set clpath=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64
set clname=cl.exe
set linkpath=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64
set linkname=link.exe
set libpath=/libpath:"C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib" /libpath:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib"
set includepath=/I "C:\Program Files\Microsoft SDKs\Windows\v7.1\Include" /I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include"
set subsystem=console
set entry=main
set libfiles=
set cfiles=hello.cpp
set objfiles=hello.obj
set path=%clpath%
%clname% %includepath% /c %cfiles%
set path=%linkpath%
%linkname% %libpath% /subsystem:%subsystem% /entry:%entry% %libfiles% %objfiles%
而這裏的輸出:
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
hello.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
hello.obj : error LNK2019: unresolved external symbol printf referenced in function main
hello.exe : fatal error LNK1120: 1 unresolved externals
鏈接程序很好,只要我並不想引用任何標準庫函數。我試着用NODEFAULTLIB和DEFAULTLIB開關搞亂,並指定標準庫直接鏈接到,無濟於事。
哦!當然,我多麼愚蠢。非常感謝!另外,我正在使用入口開關,因爲我還得到了一個未解決的對crt初始化例程的引用,但現在顯然也解決了這個問題。 – glank