Visual Studio:有关在两个项目之间链接功能的问题 [英] Visual studio: question about linking functions between two projects

查看:97
本文介绍了Visual Studio:有关在两个项目之间链接功能的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这是一个新手问题,但是无论如何.我有一个由两个项目(1个DLL和1个控制台应用程序)组成的解决方案.控制台应用程序包含DLL项目中的一些标头,当然,在构建所有标头时,链接器会告诉我有些未解析的符号. 我已经从应用程序向DLL项目中添加了一个引用(项目属性->引用->添加新引用),但这仍然无法正常工作.

I guess this is a newbie question, but anyway. I've got a solution composed of two projects (1 DLL and 1 console app). The console app includes some headers from the DLL project and of course, when building it all, the linker tells me that there are some unresolved symbols. I've already added a Reference from the app to the DLL projects (Project Properties->References->Add new Reference) but this is still not working.

我发现的唯一解决方案是复制与第二个项目中的标头对应的.cpp文件,但是我想这不是最好的方法,但是我想必须有更好的方法了?

The only solution I found is to duplicate the .cpp files corresponding to the headers in the second project but I guess this isn't the best way to do it but I guess there has to be a better way to do this?

推荐答案

我猜您使用的是Visual Studio,但不了解dllexport.

I'm going to guess you use Visual Studio and don't know about dllexport.

默认情况下,Visual Studio不会将函数的名称导出到DLL的外部.为此,您需要明确地告诉它:

Visual Studio by default does not export the names of your functions on the outside of your DLL. To do so you need to tell it that explicitly:

__declspec(dllexport) void f() {...}

并在使用DLL的那一侧:

and on the side of the one using the DLL:

__declspec(dllimport) void f();

这样,第二个将使用导入的函数,第一个将导出它.

That way the second one will use the imported function and the first will export it.

这篇关于Visual Studio:有关在两个项目之间链接功能的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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