static library works in console but not in GUI app - strange

依然范特西╮ 提交于 2019-12-11 17:57:02

问题


I have a strange error that has bothered me all day. I have a library function that I have compiled. I statically link the library to test it in a separate console application and everything builds and works ok. It is just a simple sqrt function called sqrtval at the moment. However, when I include this library in a larger graphical project then I get linker errors. I have set the Additional library directories and Additional dependency settings identically in both the console app (that works) and the graphical main app (that does not work). The error is as follows.

1

Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1 1>Copyright (C) Microsoft Corporation. All rights reserved. 1>Linking... 1>MainAppWindow.obj : error LNK2019: unresolved external symbol "double __cdecl sqrtval(double)" (?sqrtval@@YANN@Z) referenced in function "public: virtual void __thiscall MainComponent::sliderValueChanged(class juce::Slider *)" (?sliderValueChanged@MainComponent@@UAEXPAVSlider@juce@@@Z) 1>....\bin\Debug\tutorial.exe : fatal error LNK1120: 1 unresolved externals


回答1:


If your library is written in plain C, you have to declare sqrtval as:

extern "C" double sqrtval(double);



回答2:


What does the linker command line look like? Is your library listed on the linker command for the GUI application?



来源:https://stackoverflow.com/questions/3877129/static-library-works-in-console-but-not-in-gui-app-strange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!