如何将库链接到Visual Studio上的项目? [英] How to link libraries to a project on visual studio?

查看:97
本文介绍了如何将库链接到Visual Studio上的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在VS Express 2017上创建一个解决方案,其中包含两个自制的DLL:LIB_COMMON和LIB_VIEW,一个包含main.cpp并使用Qt的bin项目TEST_VIEW. 我的文件夹中有所有需要的东西,并在使用批处理文件启动解决方案时设置了环境变量.

I need to create a solution on VS Express 2017 with two self made dll, LIB_COMMON and LIB_VIEW, a bin project TEST_VIEW containing the main.cpp and using Qt. I have everything needed in my folder and set the environnement variables while launching the solution with a batch file.

但是我有两个问题.首先,我无法将Qt与要使用的项目链接起来. 其次,在属性中,我发现链接我的dll项目的唯一方法是手动添加所需的每个obj文件(是,obj文件,而不是lib ...),如本例所示. (LIB_VIEW包含标头和cpp文件VIEW_FACTORY,VIEW_View,VIEW_IView.

But I have two problems. First, I can't manage to link Qt with the projects to use . Secondly, in the properties, the only I found to link my dll project was to add by hand every obj file (yes, obj files, not lib...) needed like in this example. (LIB_VIEW contains the header and cpp files VIEW_FACTORY, VIEW_View, VIEW_IView.

linker -> entry -> additional dependencies -> $(LIB_VIEW)\Obj\$(Platform)\$(Configuration)\VIEW_FACTORY;$(LIB_VIEW)\Obj\$(Platform)\$(Configuration)\VIEW_IView;$(LIB_VIEW)\Obj\$(Platform)\$(Configuration)\VIEW_View;kernel32.lib;user32.lib;gdi32.lib;winspool32.lib      etc.

(因为obj文件的路径为: SOLUTION_NAME/LIB_VIEW/Obj/x64/Debug/ 对于lib文件: SOLUTION_NAME/LIB_VIEW/Lib/x64/Debug/ 对于包括: SOLUTION_NAME/LIB_VIEW/Inc/)

(as the path for the obj files is : SOLUTION_NAME/LIB_VIEW/Obj/x64/Debug/ for the lib file : SOLUTION_NAME/LIB_VIEW/Lib/x64/Debug/ for the includes : SOLUTION_NAME/LIB_VIEW/Inc/ )

这太糟糕了,当我不能像这样链接Qt库时. 这里有更多详细信息

This is awful and when I can't link the Qt libraries like that. Here are some more details

打包文件

set PROJECT_HOME=%~dp0
set PROJECT_TOOLS=%PROJECT_HOME%\Tools

set LIB_TOOLS=%PROJECT_HOME%\LIB_COMMON

echo "----------------------------" 
echo "--- SET_ENV_QT" 
echo "----------------------------" 

set QT_HOME==%PROJECT_TOOLS%\Qt\5.12.0\x64\5.12.0\msvc2017_64

set QT_BIN=%QT_HOME%\bin
set QT_LIB=%QT_HOME%\lib
set QT_INC=%QT_HOME%\include
set QT_QML=%QT_HOME%\qml

echo "----------------------------" 
echo "--- SET_ENV_VISUAL" 
echo "----------------------------"

set LIB_COMMON=%PROJECT_HOME%\LIB_COMMON\
set LIB_VIEW=%PROJECT_HOME%\LIB_VIEW\


set PATH=%OSPL_BIN%;%OSPL_LIB%;%PATH%

echo "----------------------------" 
echo "--- LAUNCH_SLN" 
echo "----------------------------"

"%PROJECT_HOME%\SOLUTION_NAME.sln"

如前所述,我找到了一种在主项目中包含dll的方法: 在TEST_VIEW的属性中:

As I said earlier, I found a way to include my dll in the main project : in the properties of TEST_VIEW :

C/C++ -> General -> Additionnal Include directories -> $(LIB_COMMON)/Inc;$(LIB_VIEW)/Inc;$(AdditionalIncludeDirectories);$(QtGui);

linker -> entry -> additional dependencies -> $(LIB_VIEW)\Obj\$(Platform)\$(Configuration)\VIEW_FACTORY;$(LIB_VIEW)\Obj\$(Platform)\$(Configuration)\VIEW_IView;$(LIB_VIEW)\Obj\$(Platform)\$(Configuration)\VIEW_View;kernel32.lib;user32.lib;gdi32.lib;winspool32.lib      etc.

我当然不能包含任何Qt文件,找不到它们.

Of course I can't include any Qt file, they can't be found.

我应该更改哪些属性?

如何成功包含QGuiApplication?

how can I include sucessfully QGuiApplication ?

推荐答案

我一直在链接器中添加我的个人dll的obj文件,并在那里也添加了一些Qt库.

Edit : I kept adding the obj files of my personnal dll in the linker and added some Qt lib there too.

我的问题之一是qt dll存储在特定的文件夹中,因此应用程序无法访问它们. 通过指定路径Qt/include和属性中所需的所有库添加头文件后,我制作了一个批处理文件,该文件将dll文件夹的路径添加到我的exe文件的PATH中.

One of my problems was that the qt dll's were stored in a specific folder, so the application couldn't reach them. After adding the header files by specifying the path Qt/include and all the libs needed in the properties, I made a batch file that add the path to the dll folder to the PATH of my exe file.

set PROJECT_HOME=%~dp0..\..\..\..\
set PROJECT_TOOLS=%PROJECT_HOME%\Tools

set QT_HOME=%PROJECT_TOOLS%\Qt\5.12.0\x64\5.12.0\msvc2017_64

set QT_BIN=%QT_HOME%\bin
set QT_LIB=%QT_HOME%\lib
set QT_INC=%QT_HOME%\include
set QT_QML=%QT_HOME%\qml
set QT_PLATFORM=%QT_HOME%\plugins\platforms

set QML_IMPORT_PATH=%QT_HOME%\qml\QtQuick;%QtHome%\qml\QtQuick2;%QML_IMPORT_PATH%
set PATH=%QT_BIN%;%QT_INC%;%QT_PLATFORMS%;%PATH%

TEST_VIEW3.exe

pause

哦.并且不要忘记检查通向Qt的路径.这是错误的,所以我无法在链接器中成功包含QGuiApplication ...

Oh. And don't forget to check the path to Qt. It was wrong so I couldn't include succesfully QGuiApplication within the linker...

现在可以了.我仍然有另一个错误,但此步骤已完成. 我希望这对某人有用.

Now it's okay. I still have another error but this step is done. i hope it will be usefull for someone.

这篇关于如何将库链接到Visual Studio上的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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