首页 \ 问答 \ C ++中静态库的问题(Problem with static library in C++)

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
更新时间:2022-07-17 14:07

最满意答案

编译器/链接器需要知道程序的所有部分。 一种简单的方法是将两个源文件一起编译, 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.
  • 您需要链接到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 ...
  • 首先也是最重要的: 在测试任何代码之前不要编写这么多代码。 从小而简单开始,让一些东西完美地工作(即使它什么都不做),一次增加一点复杂性,在每一步测试, 永远不要添加到不起作用的代码。 更具体地说,查看变量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, ...
  • 事实证明,参数无法在命令行上传递,需要在配置文件中进行更改。 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- ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)