C ++中静态库的问题(Problem with static library in C++)
我正在尝试使用Visual C ++ 2005(非托管C ++)中创建的静态库。 我声明了一个函数“int myF(int a);” 到.h文件中,我在.cpp文件中实现它,我编译它 - 生成.lib文件。
我在VC ++ 2005(也是原生C ++)中创建了一个新项目(一个单独的解决方案),我添加了包含文件和lib文件的路径; 当我调用函数myF时,链接器报告错误:“错误LNK2019:函数_main中引用的未解析的外部符号_myF”。 如果我在与库项目相同的解决方案中创建客户端项目,然后添加对库项目的引用,它可以工作,但我不打算实现这样的一切,而是将外部库添加到我的项目中。 。
哪里不对?
谢谢。
I'm trying to use a static library created by me in Visual C++ 2005 (unmanaged C++). I declare one function "int myF(int a);" into a .h file, I implement it in a .cpp file, I compile it - the .lib file is produced.
I create a new project (a separate solution) in VC++ 2005 (also native C++), I add the paths for the include file and the lib file; when I invoke the function myF the linker reports an error: "error LNK2019: unresolved external symbol _myF referenced in function _main". if I create the client project in the same solution as the library project and then add a reference to the library projects, it works, but I'm not going to implement everything like this, but rather to add external libraries to my projects...
What is wrong?
Thank you.
原文:https://stackoverflow.com/questions/187627
最满意答案
编译器/链接器需要知道程序的所有部分。 一种简单的方法是将两个源文件一起编译,
gcc main.cpp qsort.cpp
,以便将生成的目标文件传递给链接器。或者,如果单独编译,则需要将两个目标文件都传递给链接器。
The compiler/linker need to know about all the parts of your program. One simple way to do this is to compile both source files together,
gcc main.cpp qsort.cpp
, so that it will pass both generated object files to the linker.Or if compiling separately, you need to pass both object files to the linker.
相关问答
更多-
您需要将Ws2_32.lib添加到链接器命令以解析该功能。 You need to add Ws2_32.lib to your linker command to resolve that function.
-
无法解析的外部符号(Unresolved external symbol)[2023-12-23]
您需要链接到Dwrite.lib,其中包含DWriteCreateFactory的实现 看到这里的文件。 底部的Requirements部分解释了需要包含和链接到使用错误引用的函数的内容。 您可以通过添加该行来解决此问题 #pragma comment(lib, "Dwrite") You need to link to Dwrite.lib, which includes the implementation of DWriteCreateFactory See here for documentati ... -
使用标头和类定义文件时未解决的外部符号错误(Unresolved External Symbol Errors when using header and class definition files)[2023-07-21]
首先也是最重要的: 在测试任何代码之前不要编写这么多代码。 从小而简单开始,让一些东西完美地工作(即使它什么都不做),一次增加一点复杂性,在每一步测试, 永远不要添加到不起作用的代码。 更具体地说,查看变量custTax 。 您在RestaurantCheck.h中将其声明为静态成员变量,但在RestaurantCheck.cpp中将其定义为全局变量 double custTax = 0; 正确的方法是这样的: double RestaurantCheck::custTax = 0; 您似乎遇到了与ci ... -
此链接http://lists.boost.org/boost-users/2010/04/57957.php表明构建boost库和项目之间的编译器标志存在一些差异 This link http://lists.boost.org/boost-users/2010/04/57957.php suggests that there is some difference in the compiler flags between building the boost libraries and your pro ...
-
我将$(OPENCV_DIR)\ staticlib添加到库目录,并且还添加到链接器 - >其他库Directores并将以下内容添加到链接器 - >输入 - >其他依赖项 : ippicvmt.lib IlmImfd.lib libtiffd.lib libpngd.lib libjasperd.lib libjpegd.lib libwebpd.lib zlibd.lib comctl32.lib 现在这个例子很有用。 I added $(OPENCV_DIR)\staticlib to Librar ...
-
编译器/链接器需要知道程序的所有部分。 一种简单的方法是将两个源文件一起编译, gcc main.cpp qsort.cpp ,以便将生成的目标文件传递给链接器。 或者,如果单独编译,则需要将两个目标文件都传递给链接器。 The compiler/linker need to know about all the parts of your program. One simple way to do this is to compile both source files together, gcc mai ...
-
从MSDN看来,您需要链接到Normaliz.dll 。 尝试在链接器 - >输入 - >附加依赖项中添加Normaliz.lib It seems from MSDN, you need to link against Normaliz.dll. Try adding Normaliz.lib in Linker -> Input -> Additional Dependencies
-
链接器采用入口点的默认名称。 你有几个选择。 1.在平台上使用C库,因为你使用MASM,我认为你不想这样做。 2.将您的MAIN重命名为_WinMainCRTStartup 3.在Link.exe命令行中使用“-entry:MAIN”(您可能需要“public MAIN”行) The linker assumes the default name for entry point. You have a few options. 1. Use the C libraries on the platform, ...
-
在Windows上编译GDAL 1.11.0时未解析的外部符号(unresolved external symbol when compiling GDAL 1.11.0 on windows)[2022-04-24]
事实证明,参数无法在命令行上传递,需要在配置文件中进行更改。 It turned out that the arguments could not be passed on command line and needed to be changed in the config file. -
未解析的外部始终是链接错误。 甚至还有它的名字:LNK2019。 它告诉你它找不到sky :: OutOfRange :: OutOfRange()的实现 你把它放在某个地方的标题中并且你已经调用了它,但是你还没有链接到实现它的库。 我们无法告诉您哪些库实现了它或它在硬盘上的位置。 您必须查阅OutOfRange的文档,它的作者或您自己。 我可以告诉你,你需要检查:右键单击可执行项目 - > properties-> linker-> general->其他库目录属性 - > linker-> input- ...