I made a visual studio project using CMake, and when I try to compile it I get these errors. The error seem to be related to QDomDocument objects only, I dont get any link error related to other Qt classes;
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __cdecl QDomNode::~QDomNode(void)" (__imp_??1QDomNode##QEAA#XZ) referenced in function "private: void __cdecl Graph::readFromFile(class QString)" (?readFromFile#Graph##AEAAXVQString###Z) Gps_test C:\Users\Cristi\Desktop\an2 sem 2\QT\gps_test1\build\graph.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class QDomNodeList __cdecl QDomNode::childNodes(void)const " (__imp_?childNodes#QDomNode##QEBA?AVQDomNodeList##XZ) referenced in function "private: void __cdecl Graph::readFromFile(class QString)" (?readFromFile#Graph##AEAAXVQString###Z) Gps_test C:\Users\Cristi\Desktop\an2 sem 2\QT\gps_test1\build\graph.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __cdecl QDomDocument::setContent(class QIODevice *,class QString *,int *,int *)" (__imp_?setContent#QDomDocument##QEAA_NPEAVQIODevice##PEAVQString##PEAH2#Z) referenced in function "private: void __cdecl Graph::readFromFile(class QString)" (?readFromFile#Graph##AEAAXVQString###Z) Gps_test C:\Users\Cristi\Desktop\an2 sem 2\QT\gps_test1\build\graph.obj 1
This is my CMake file for the source files:
# Defines the minimum CMake version required for the CMakeLists.txt file
# to be correctly interpreted. Older versions of CMake may not contain
# all the features to "understand" this file.
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
# Defines the name and language the project will be using.
project(Gps_test LANGUAGES CXX)
# Set the path to the Qt5 installation's CMake instructions.
set(Qt5_DIR "D:/qt/5.10.1/msvc2017_64/lib/cmake/Qt5")
# Automatically add the current source and build directories to the
# include path.
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Automatically create Qt5 MOCs at compile time.
set(CMAKE_AUTOMOC ON)
# Automatically create Qt5 UICs at compile time.
set(CMAKE_AUTOUIC ON)
# Include Qt5 and its widgets.
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui)
# Add to PROJECT_SOURCES variable all the filenames inside
# ${CMAKE_CURRENT_SOURCE_DIR} which respect the given pattern.
file(GLOB PROJECT_SOURCES "*.cpp")
# Instruct CMake to create an executable based on all the .cpp
# sources of the project. You may, for example, create multiple
# executables based on different source files, inside the same
# project.
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
# Specify libraries or flags to use when linking a given target.
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets)
Anyone knows how I can fix this? Thanks.
Those are part of the Xml component. Try this:
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Xml)
...
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Xml
)
Related
I am building Field3D which links to Boost's thread library. The building environment is listed as follows:
Windows 10 version 1803 64bit
Visual Studio 2015 Update 3
CMake 3.11.4
Release x64 DLL mode in VS
Field3D source package is downloaded from master branch of https://github.com/imageworks/Field3D
Boost is pre-compiled binary of version 1.67.0 for VS2015 (v14.0) 64bit, downloaded from https://sourceforge.net/projects/boost/files/boost-binaries and installed under C:\local\boost_1_67_0 directory.
Doxygen and HDF5 installed properly.
The CMake command line to set up VS2015 is:
cmake -DCMAKE_CONFIGURATION_TYPES=Release -DBUILD_SHARED_LIBS=ON
-DCMAKE_INSTALL_PREFIX=C:...\Field3D-master\install -DDOXYGEN_EXECUTABLE="C:\Program Files\doxygen\bin\doxygen.exe" -DHDF5_ROOT="C:\Program Files\HDF_Group\HDF5\1.10.2" -DBOOST_ROOT=C:\local\boost_1_67_0 -DBOOST_INCLUDEDIR=C:\local\boost_1_67_0\boost -DBOOST_LIBRARYDIR=C:\local\boost_1_67_0\lib64-msvc-14.0 -DIlmbase_Base_Dir=C:...\openexr-develop\IlmBase\install_ -G"Visual Studio 14 2015 Win64" ..
Then I open the generated field3d.sln in VS2015 and try to build Field3D project. Errors are reported as below:
1>------ Build started: Project: Field3D, Configuration: Release x64 ------
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "public: virtual __cdecl boost::detail::thread_data_base::~thread_data_base(void)" (??1thread_data_base#detail#boost##UEAA#XZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "public: void __cdecl boost::thread::detach(void)" (?detach#thread#boost##QEAAXXZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "class boost::thread::id __cdecl boost::this_thread::get_id(void)" (?get_id#this_thread#boost##YA?AVid#thread#2#XZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "public: class boost::thread::id __cdecl boost::thread::get_id(void)const " (?get_id#thread#boost##QEBA?AVid#12#XZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "bool __cdecl boost::this_thread::interruptible_wait(void *,struct boost::detail::mono_platform_timepoint const &)" (?interruptible_wait#this_thread#boost##YA_NPEAXAEBUmono_platform_timepoint#detail#2##Z) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "private: bool __cdecl boost::thread::join_noexcept(void)" (?join_noexcept#thread#boost##AEAA_NXZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "public: bool __cdecl boost::thread::joinable(void)const " (?joinable#thread#boost##QEBA_NXZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1>libboost_thread-vc140-mt-x64-1_67.lib(thread.obj) : error LNK2005: "private: bool __cdecl boost::thread::start_thread_noexcept(void)" (?start_thread_noexcept#thread#boost##AEAA_NXZ) already defined in boost_thread-vc140-mt-x64-1_67.lib(boost_thread-vc140-mt-x64-1_67.dll)
1> Creating library C:/.../Field3D-master/build/Release/Field3D.lib and object C:/.../Field3D-master/build/Release/Field3D.exp
1>C:\...\3rd-parties\Field3D-master\build\Release\Field3D.dll : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
The cause of these errors, as far as I can see, is that the line 46 of Field3D's CMakeLists.txt
FIND_PACKAGE (Boost COMPONENTS regex thread)
specifies linking boost's thread component, which in turn leads to linking import library C:\local\boost_1_67_0\lib64-msvc-14.0\boost_thread-vc140-mt-x64-1_67.lib, as can be checked in Project Properties -> Linker -> Input -> Additional Dependencies in VS. But somehow Field3D insists on additionally linking to the static library of Boost's thread component which is libboost_thread-vc140-mt-x64-1_67.lib (you can see it in the error messages), thus causing name conflicts. If I temporarily remove "thread" from the FIND_PACKAGE's COMPONENTS list to let Field3D link to the static library as it insists, the Field3D project can build correctly.
Because I wanna build Field3D based on the dynamic DLL of Boost library, my question is: Why does Field3D insist on linking to the static boost library "libboost_thread-vc140-mt-x64-1_67.lib"? Where is this rule introduced? How to suppress linking static thread library of Boost? I have checked CMakeLists.txt, and variables like Boost_LIBRARY_DIRS, Boost_LIBRARIES and Field3D_BIN_Libraries therein but they do not contain static library filename libboost_thread-vc140-mt-x64-1_67.lib. I know that #pragma comment (linker, ...) can also require linking to some user-defined library, but there is no such directive in Field3D source package whatsoever. So I am at my wit's end and post this question here in hope that someone can help me figure out where on earth the linking postulation to the static library of Boost's thread component comes from. Some minor modification may be needed to reproduce the issue but I think the information provided above should cover most of the build for a veteran. If you need any other info to troubleshoot this problem please let me know. Thank you.
After another bunch of hours to check Field3D's building process, I believe the problem is Field3D's failure to make use of Boost's mechanism to disable automatic linking and to enable dynamic linking on Windows. An issue ticket is submitted in hope that the developers of Field3D can fix it in future: https://github.com/imageworks/Field3D/issues/96. Briefly, add the following two commands to copy INTERFACE_COMPILE_DEFINITIONS property of Boost::disable_autolinking and Boost::dynamic_linking import targets to Field3D project
TARGET_COMPILE_DEFINITIONS( Field3D PRIVATE $<TARGET_PROPERTY:Boost::disable_autolinking,INTERFACE_COMPILE_DEFINITIONS> )
TARGET_COMPILE_DEFINITIONS( Field3D PRIVATE $<TARGET_PROPERTY:Boost::dynamic_linking,INTERFACE_COMPILE_DEFINITIONS> )
after line 189 of CMakeLists.txt.
Please point out if I have made any mistake.
I am trying to use this PCL library, and downloaded the all-in-one installer(1.8.1-mscv2017-win64).
Added all the directories for the "Include Directories".
Added all the corresponding library folders to the "Library Directories".
System Path checked.
But it still gives me about 30 Link errors, like the following two:
LNK2019 unresolved external symbol "void __cdecl pcl::console::print(enum pcl::console::VERBOSITY_LEVEL,char const *,...)" (?print#console#pcl##YAXW4VERBOSITY_LEVEL#12#PEBDZZ) referenced in function "public: void __cdecl pcl::detail::FieldMapper<struct pcl::PointXYZRGBA>::operator()<struct pcl::fields::rgba>(void)" (??$?RUrgba#fields#pcl###?$FieldMapper#UPointXYZRGBA#pcl###detail#pcl##QEAAXXZ) RealSensewithPCL
LNK2001 unresolved external symbol "public: virtual int __cdecl pcl::PCDReader::readHeader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct pcl::PCLPointCloud2 &,class Eigen::Matrix<float,4,1,0,4,1> &,class Eigen::Quaternion<float,0> &,int &,int &,unsigned int &,int)" (?readHeader#PCDReader#pcl##UEAAHAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEAUPCLPointCloud2#2#AEAV?$Matrix#M$03$00$0A#$03$00#Eigen##AEAV?$Quaternion#M$0A##7#AEAH4AEAIH#Z)
Here is the update for my issues about the link errors after the steps I mentioned in the post:
Add all the directories for the "Include Directories".
Add all the corresponding library folders to the "Library Directories".
The link error LNK2019 is caused by the missing dependencies ('.lib' files).
Best way to add them is same as the method mentioned in this post:
In visual studio how to include all .libs in a folder
Basically, go to Properties->Configuration Properties->Linker->Command Line, add the path of all the ".lib" files to the "Additional Options".
Make sure you only add the right .lib files for your current Config (Debug or Release). For the "Debug" mode, you need add the .lib files with "gd" or "debug" in their filenames. Otherwise, you may have new link errors(LNK2038) similar to this one:
LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in cloud_viewer.obj
Here is what I put in my command line(All paths are separated by space):
"C:\Program Files\PCL 1.8.1\3rdParty\VTK\lib\*gd.lib" "C:\Program Files\PCL 1.8.1\3rdParty\Boost\lib\*gd-1_64.lib" "C:\Program Files\PCL 1.8.1\3rdParty\FLANN\lib\*gd.lib" "C:\Program Files\PCL 1.8.1\lib\*_debug.lib"
Hope this answer can free you from the struggling of setting things up and start rolling!
This is my code in Visual Studio C++
#include "stdafx.h"
#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace cv;
int main(int argc, char** argv[]) {
IplImage* img = cvLoadImage("logo.jpg");
cvNamedWindow("Test", CV_WINDOW_AUTOSIZE);
cvShowImage("Test", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Test");
return 0;
}
I am using OpenCV 2.4.6 and Visual Studio 2010. This is the error:
openCV_testing.obj : error LNK2019: unresolved external symbol _cvDestroyWindow
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvReleaseImage
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvWaitKey referenced in
function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvShowImage referenced
in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvNamedWindow
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvLoadImage referenced
in function _main
Please help.
'unresolved external symbol' means that you're not linking with required library.
Go to Properties -> Linker -> Additional Library dependencies and add path to OpenCV libs.
First check
How to build applications with OpenCV inside the Microsoft Visual Studio
If you still suffer from the same problem, you could be under one of the below cases.
Your active solution platform is x86 but you are trying to link x64 OpenCV libraries.
Your active solution platform is X64 but you are trying to link x86 OpenCV libraries.
If you are under one of these cases, check
Compiling a 64-bit Application in Microsoft Visual Studio Express 2010
Add these into your code:
#pragma comment (lib, "opencv_core248d.lib")
#pragma comment (lib, "opencv_highgui248d.lib")
#pragma comment (lib, "opencv_imgproc248d.lib")
#pragma comment (lib, "opencv_video248d.lib")
#pragma comment (lib, "opencv_features2d248d.lib")
It worked for me.
i searched a lot for the same problem this was the best solution i had found and it worked for me.
Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):
C:\OpenCV2.3\build\include\opencv
C:\OpenCV2.3\build\include\opencv2
C:\OpenCV2.3\build\include
I know this is not about the OpenCV library, but I already had a problem importing Tiny-Process library. My .lib file was linked correctly in Configuration Properties -> Linker -> Additional Library dependencies and the Additionnal Include Directories were correctly added but the the functions definition (s) were still not found and I was getting the LNK2019 error.
To fix the issue, I had to go in the library project properties, change the Character Set property in Configuration Properties -> Advanced Character Set and change the value Use Multi-Byte Character Set to Use Unicode Character Set.
After recompiling the library and using the new .lib file, it was working.
I have received a Visual C++ QT based project from our customer. I have installed QT libraries then I have compiled the project. The Project was compiled without any problems.
Now, I need to include a new additional GUI interface with the existing project. I have created a GUI in QT designer then saved in the source directory of VC++ project. Then I have written .h and .cpp file for new GUI and could call this interface. Now I need to include SIGNALS and SLOTS, when I include Q_OBJECT in .h file. I have compilation error.
These are the errors, please help me to solve this problem:
unresolved external symbol "public: virtual struct QMetaObject const * __thiscall BetaLineServer::metaObject(void)const " (?metaObject)
unresolved external symbol "public: virtual void * __thiscall BetaLineServer::qt_metacast(char const *)"
unresolved external symbol "public: virtual int __thiscall BetaLineServer::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#
Any time you add a Q_OBJECT macro to a class you need to be sure to rerun qmake and then compile.
All you need is to compile the header files with moc that contain Q_OBJECT macro. And how to do that? here it is
You can manually type commands for compiling moc or uic files OR
-> Install Qt-VS addin. http://qt.nokia.com/downloads/visual-studio-add-in
-> Now, open visual studio and create a new Qt project as described in here and then
-> Right click on a header file that contains the Q_OBJECT macro you should find something like below. Copy these commands into your project.
-> Replace the header file name with yours in the 'Command Line' command
-> compile once and that should generate moc_xxxxx.cpp files, include them in your project.
For future reference, if you create a Qt project in VS using this plugin you should have these commands automatically added
You probably just need to add your .ui, .cpp and .h files to the project file.
Qt will run 'moc' on the ui file if it's listed there, which creates source code to supply your missing symbols.
Exclude .h file from the project and include it again - moc_.cpp will appear in the "Generated Files", and linking errors are disapeared.
I was using a ITK library. When I wrote a sample program using this library, I've got following linker errors. As we can see these all "unresolved" symbols are Windows API functions and these windows API functions were used by ITK library and not my program.
Error 1 error LNK2019: unresolved external symbol _SnmpUtilVarBindFree#4 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 2 error LNK2019: unresolved external symbol _SnmpUtilOidNCmp#12 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 3 error LNK2019: unresolved external symbol _SnmpUtilOidCpy#8 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 4 error LNK2019: unresolved external symbol _WSAStartup#8 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 5 error LNK2019: unresolved external symbol __imp__UuidCreate#4 referenced in function "private: static bool __cdecl gdcm::Util::GenerateUUID(unsigned char *)" (?GenerateUUID#Util#gdcm##CA_NPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 6 error LNK2019: unresolved external symbol _gethostbyname#4 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 7 error LNK2019: unresolved external symbol _gethostname#8 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 8 error LNK2019: unresolved external symbol _WSACleanup#0 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
These errors have raised few questions in my mind. For some of them I think I know the answers but I need confirmation if I'm right or wrong.
These Windows API functions are used in gdcmUtil.cpp (because it says gdcmUtil.obj). So, compiler compiles gdcmUtil.cpp to (say)gdcmUtil.asm and it is assembler assembles it to gdcmUtil.obj. Since while compiling the library we are not generating any exe files. These *.obj files aren't linked against any other *.obj. So, windows API symbols are still external symbols for that module and thus left unresolved. Right?
Who is generating the *.LIB file? I mean compiler is generating *.s file and Assembler is generating *.obj file and we are not using linker. So, from where did we get *.lib file? Who packed all *.obj files to a *.lib file?
How are Windows API applications (programs that are written in C and use Windows API) are compiled? I mean, because its a standalone applications how are these WIN32 API symbols resolved? Assuming, I've written such program can anyone tell me what do I need to sucessfully build application?
I know that Windows API is implemented in kernel32.dll, gdi32.dll, user32.dll (which may in turn import some other dlls like wsock32.dll for networking API etc.) but the question is How to use these functions in Windows API functions in a C program. I mean how to dynamically link against these DLLs
In my quest to find answer to my problem of Linker errors. I discovered that I must add wsock32.lib (for WinSock 1.1) or ws2_32.lib(for WinSock 2) or snmpapi.lib to Linker Input.
Since when Windows API is being statically linked?
Since when windows API is being shipped in static libraries (*.lib files)?
In which directory can I find all these strange *.lib files?
Now, Is there any alternative solution other than adding *.lib files to linker input files? because when ever I use some new ITK library function, I get a new linker error. I've to Google to find in which *.lib file this specific symbol (window api function) belongs to then add that *.lib file to my linker input. Its driving me crazy! Is there any sane way?
Yes, that's right.
Who is generating what .lib file? A static library is normally generated by the lib utility. A library for a dll is normally generated by the linker.
You resolve Windows symbols by linking with the right libraries.
Again, by linking against the appropriate library (e.g., kernel32.lib, gdi32.lib and user32.lib for the three DLLs you mentioned).
It's not statically linked. You link against the library. In the case of a library for a DLL (such as those listed above) the linker uses that to embed a record into the executable that tells the loader which DLL to use to resolve those symbols. The .lib files are in the lib subdirectory of wherever you installed the SDK (typically something like C:\Program Files\Microsoft SDKs\Windows\v6.0A. Normally the SDK installer will add those where necessary so you don't have to explicitly specify that directory when linking from the command line or within Visual Studio.
There are a few, though it's open to question whether they're really an improvement. One possibility is to use a pragma to tell the linker to use a particular library:
#pragma comment(lib, "ws2_32.lib")
This is particularly useful in a header if it uses functions that depend on a particular library.