视觉工作室源文件构建命令 [英] visual studio source files building order

查看:107
本文介绍了视觉工作室源文件构建命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中有n个cpp文件。'A'是具有main函数的源文件,'B'是包含将由'A'使用的函数定义的另一个源文件。 p>

A.cpp

#includestdafx.h
#includebh
int main()
{
add(5,4);
return 0;
}



Bh



includestdafx.h
void add(int a,int b);



B.cpp



#includestdafx.h
void add(int a,int b)
{
cout< a + b);
}



但是构建顺序就像b.cpp之后的a.cpp,所以add函数应该通过链接器解析。
我如何解决构建顺序问题?



编辑1:我的构建文件日志: -



Build started 22-11-2014 15:57:11。
1>项目C:\Users\Admin\Documents\Visual工作室2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj节点2(建设目标(S))。
1>链接:
C:\Program文件(x86)\Microsoft Visual Studio 12.0 \VC\bin\link.exe / ERRORREPORT:PROMPT / OUT:C:\ Users\Admin\Documents\Visual工作室2013\Projects\ConsoleApplication2\Release\ConsoleApplication2.exe/增量:NO / NOLOGO / LIBPATH:D:\Glut / LIBPATH:D:\OpenCV\\ \\opencv\build\x86\vc11\lib opencv_core246.lib opencv_features2d246.lib opencv_haartraining_engine.lib opencv_calib3d246.lib opencv_highgui246.lib opencv_imgproc246.lib opencv_legacy246.lib opencv_ml246.lib opencv_objdetect246.lib opencv_video246.lib glut32.lib asmlibrary.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib / MANIFEST / MANIFESTUAC:level ='asInvoker'uiAccess ='假'/清单:嵌入/ DEBUG / PDB:C:\Users\Admin\Documents\Visual工作室2013\Projects\ConsoleApplication2\Release\ConsoleApplication2.pdb/子系统:CONSOLE / OPT :REF / OPT:ICF / LTCG / TLBID:1 / DYNAMICBASE / NXCOMPAT / IMPLIB:C:\Users\Admin\Documents\Visual工作室2013\Projects\ConsoleApplication2\Release\ConsoleApplication2.lib / MACHINE:X86 / SAFESEH Release\CLM.obj
Release\FCheck.obj

  FDet.obj 

Release\IO.obj

Release\Patch.obj

Release\ PAY.obj

Release\PDM.obj

Release\Tracker.obj

Release\updated_facetracker_v2.obj

Release\glm。 obj

Release\glmimg.obj

Release\glmimg_devil.obj

Release\glmimg_jpg.obj

Release\glmimg_png.obj

Release\glmimg_sdl.obj

Release\glmimg_sim.obj

Release\glm_util.obj

Release\stdafx.obj

1> updated_facetracker_v2.obj:error LNK2001:未解析的外部符号void __cdecl glmDraw(struct _GLMmodel *,unsigned int)(?glmDraw @ @ YAXPAU_GLMmodel @@ I @ Z)
1> updated_facetracker_v2.obj:error LNK2001:未解析的外部符号struct _GLMmodel * __cdecl glmReadOBJ(char *)(?glmReadOBJ @@ YAPAU_GLMmodel @@ PAD @ Z)
1分配> C:\Users\Admin\Documents\Visual工作室2013\Projects\ConsoleApplication2\Release\ConsoleApplication2.exe:致命错误LNK1120:2无法解析的外部
1 GT;完成建设项目C:\Users\Admin\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj(构建目标) - 失败。

建立失败。



:00:00.81



这是原始的项目构建文件,这里的glm.c是编译后的updated_facetracker_v2.cpp文件和glm.c没有任何错误。

解决方案

您的链接器fais,因为 B.cpp 。编译器无法为 B.cpp 创建一个对象,因为对象不存在,链接器不能找到它,并给出错误。

更改 B.cpp

from:

  #includestdafx.h
void add(int a, int b)
{
cout<(a + b);
}


b $ b

到:

  #includestdafx.h
#include< iostreams>

void add(int a,int b)
{
std :: cout<<(a + b)<<< std :: endl;
}

构建顺序无所谓:编译器获取每个源文件并创建一个目标文件。链接器获取目标文件并尝试将它们链接到目标可执行文件。



此外,你的主体也是错误的:



change:

  add(5 + 4); 

到:

 code> add(5,4); 

您尝试链接 add(int),而您的 B.cpp 中的函数具有签名 add(int,int)到链接器。


i have n number of cpp files in a project.'A' is the source file which will have main function,'B' is an another source file which contains function definition which will be used by 'A'.

A.cpp #include "stdafx.h" #include "b.h" int main() { add(5,4); return 0; }

B.h

#include "stdafx.h" void add(int a ,int b);

B.cpp

#include "stdafx.h" void add(int a,int b) { cout<<(a+b); }

but the build order is like a.cpp after b.cpp so the add function should be unresolved by linker. how can i solve the build order problem?

Edit 1:my build file log:-

Build started 22-11-2014 15:57:11. 1>Project "C:\Users\Admin\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj" on node 2 (Build target(s)). 1>Link: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\Admin\Documents\Visual Studio 2013\Projects\ConsoleApplication2\Release\ConsoleApplication2.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:D:\Glut /LIBPATH:D:\OpenCV\opencv\build\x86\vc11\lib opencv_core246.lib opencv_features2d246.lib opencv_haartraining_engine.lib opencv_calib3d246.lib opencv_highgui246.lib opencv_imgproc246.lib opencv_legacy246.lib opencv_ml246.lib opencv_objdetect246.lib opencv_video246.lib glut32.lib asmlibrary.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\Admin\Documents\Visual Studio 2013\Projects\ConsoleApplication2\Release\ConsoleApplication2.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\Admin\Documents\Visual Studio 2013\Projects\ConsoleApplication2\Release\ConsoleApplication2.lib" /MACHINE:X86 /SAFESEH Release\CLM.obj Release\FCheck.obj

     Release\FDet.obj

     Release\IO.obj

     Release\Patch.obj

     Release\PAW.obj

     Release\PDM.obj

     Release\Tracker.obj

     Release\updated_facetracker_v2.obj

     Release\glm.obj

     Release\glmimg.obj

     Release\glmimg_devil.obj

     Release\glmimg_jpg.obj

     Release\glmimg_png.obj

     Release\glmimg_sdl.obj

     Release\glmimg_sim.obj

     Release\glm_util.obj

     Release\stdafx.obj

 1>updated_facetracker_v2.obj : error LNK2001: unresolved external symbol "void __cdecl glmDraw(struct _GLMmodel *,unsigned int)" (?glmDraw@@YAXPAU_GLMmodel@@I@Z)
 1>updated_facetracker_v2.obj : error LNK2001: unresolved external symbol "struct _GLMmodel * __cdecl glmReadOBJ(char *)" (?glmReadOBJ@@YAPAU_GLMmodel@@PAD@Z)
 1>C:\Users\Admin\Documents\Visual Studio 2013\Projects\ConsoleApplication2\Release\ConsoleApplication2.exe : fatal error LNK1120: 2 unresolved externals
 1>Done Building Project "C:\Users\Admin\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj" (Build target(s)) -- FAILED.

Build FAILED.

Time Elapsed 00:00:00.81

this is the original projects build file here glm.c is compiled built after the updated_facetracker_v2.cpp file and glm.c did not have any error."

解决方案

Your linker fais, because B.cpp doesn't compile. The compiler fails to create an object for B.cpp. Since the object isn't there, the linker can't find it, and gives the error. There should be an error about B.cpp further up the error log.

Change B.cpp from:

#include "stdafx.h"
void add(int a,int b)
{
    cout<<(a+b);
}

to:

#include "stdafx.h"
#include <iostreams>

void add(int a,int b)
{
    std::cout<<(a+b) << std::endl;
}

Build order doesn't matter: The compiler takes each source file and creates an object file. The linker takes the object files and tries to link those to your target executable. The order your compiler generates the object files shouldn't matter.

Also, your main is faulty too:

change:

      add(5+4);

to:

      add(5, 4);

You are trying to link against add(int) while your function in B.cpp has the signature add(int, int) which is a different function according to the linker.

这篇关于视觉工作室源文件构建命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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