I am getting a boost linking error when using both PCL and cgal in a project (as well as a redefinition warning). PCL and cgal examples both run fine so the installation should be good.
My program to test looks like this:
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <pcl/visualization/cloud_viewer.h>
int
main()
{
std::cout << "Test "<< std::endl;
return 0;
}
The error that I get is pasted below:
1>------ Build started: Project: PC_Svr2, Configuration: Debug x64 ------
1>cloud_viewer.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>C:\Program Files\PCL 1.8.1\include\pcl-1.8\pcl/visualization/boost.h(51,1): warning C4005: 'BOOST_PARAMETER_MAX_ARITY': macro redefinition
1>C:\dev\CGAL-5.0.2\include\CGAL/config.h(115): message : see previous definition of 'BOOST_PARAMETER_MAX_ARITY'
1>cloud_viewer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" (__imp_?system_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat#system#boost##YAXXZ)
1>cloud_viewer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (__imp_?generic_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "public: __cdecl boost::thread_exception::thread_exception(int,char const *)" (??0thread_exception#boost##QEAA#HPEBD#Z)
1>C:\Users\PCL_Project\PC_svr2\build\Debug\PC_Svr2.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "PC_Svr2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
When I exclude the PCL include the program runs fine, but when I exclude the cgal include i get a very similar error:
1>------ Build started: Project: PC_Svr2, Configuration: Debug x64 ------
1>cloud_viewer.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>cloud_viewer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" (__imp_?system_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat#system#boost##YAXXZ)
1>cloud_viewer.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (__imp_?generic_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "public: __cdecl boost::thread_exception::thread_exception(int,char const *)" (??0thread_exception#boost##QEAA#HPEBD#Z)
1>C:\Users\PCL_Project\PC_svr2\build\Debug\PC_Svr2.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "PC_Svr2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
I am not sure but I suspect that it might have something to do with my CMakeLists.txt, which I will also paste below:
cmake_minimum_required(VERSION 3.1...3.15)
project(PC_Svr2)
find_package(CGAL QUIET)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (PC_Svr2 cloud_viewer.cpp)
target_link_libraries(PC_Svr2 CGAL::CGAL ${PCL_LIBRARIES})
Does anyone know what the problem might be?
I seem to have found the answer. It seems to have been a problem with boost and making the boost library static solved the problem. (I found this question about the same problem: C++ using two incompatible libraries together, what are the options?)
So to fix it check the Advanced option in the CMake GUI and then under CGAL check CGAL_Boost_USE_STATIC_LIBS.
You are misisng boost in your CMakeLists.txt. Your test runs fine without PCL because CGAL's header does not need boost, and I guess PCL's does.
You need to add
find_package(Boost COMPONENTS system) and
target_link_libraries(PC_Svr2 CGAL::CGAL ${PCL_LIBRARIES} Boost::system).
It should be ok after that.
If not, check what components you need and change your configuration file accordingly.
Note that most of the time, a linking error means a problem with target_link_libraries(), either it is missing, or the values given to it are wrong.
Related
Problem
I am getting linker errors when building my project. The project has no trouble finding wxWidgets headers. I have looked at the wxWidgets minimal example and recreated it in order to verify that my build from source worked properly. I used cmake in VSCode to do the build using the cmake extension.
The wxWidgets cmake generated fine and the build of wxwidgets appears to have gone fine. I am using the Visual Studio 2022 amd64 toolset to do the compile. (I installed VS2022 Community Edition for the compiler only).
It looks like it is building DLL for the libraries. I would prefer static libraries but for an initial run I didnt think it mattered. I link my application to wx::net wx::core wx::base as recommended. I thought that this would take care of linking when I go to build.
When I go to build my overall application utilizing the wxWidgets library, I get these linker errors.
What am I doing wrong here? Im obviously not configuring something correctly for it to find the library, but I am kind of stumped here.
Linker Errors
[build] ProjectName.obj : error LNK2001: unresolved external symbol "protected: static class wxAppConsole * (__cdecl* wxAppConsoleBase::ms_appInitFn)(void)" -snipped-
[build] ProjectName.obj : error LNK2001: unresolved external symbol "protected: static class wxAppConsole * wxAppConsoleBase::ms_appInstance" -snipped-
[build] MainWindow.obj : error LNK2001: unresolved external symbol "void (__cdecl* wxTheAssertHandler)(class wxString const &,int,class wxString const &,class wxString const &,class wxString const &)"-snipped-
[build] MainWindow.obj : error LNK2001: unresolved external symbol "bool wxTrapInAssert" (?wxTrapInAssert##3_NA) -snipped-
[build] MainWindow.obj : error LNK2001: unresolved external symbol "class wxMBConv * wxConvLibcPtr" (?wxConvLibcPtr##3PEAVwxMBConv##EA) -snipped-
[build] MainWindow.obj : error LNK2001: unresolved external symbol "public: static unsigned __int64 const wxString::npos" (?npos#wxString##2_KB)-snipped-
[build] MainWindow.obj : error LNK2001: unresolved external symbol "class wxSize const wxDefaultSize" (?wxDefaultSize##3VwxSize##B)-snipped-
[build] MainWindow.obj : error LNK2001: unresolved external symbol "class wxPoint const wxDefaultPosition" (?wxDefaultPosition##3VwxPoint##B)-snipped-
[build] MainWindow.obj : error LNK2001: unresolved external symbol "char const * const wxFrameNameStr" (?wxFrameNameStr##3QBDB)-snipped-
[build] C:\path\to\executable\ProjectName.exe : fatal error LNK1120: 9 unresolved externals -snipped-
[build] Build finished with exit code 1
Project Layout
Pretty basic project layout. I am building a GUI application and I am logically separating out the ui source code.
This is basically a recreation of the minimal wxWidgets example where you have an entry point (Projectname.hpp and ProjectName.cpp provide this) and a main window/frame (MainWindow.hpp and MainWindow.cpp provide this). The ProjectName application will do the wxIMPLEMENT_APP(ProjectName) and will hold a pointer to a MainWindow. The MainWindow is shown using the OnInit Function.
ProjectName/
build/
external/
wxWidgets-3.1.6/
-CMakeLists.txt
source/
ui/
-MainWindow.hpp
-MainWindow.cpp
-ProjectName.hpp
-ProjectName.cpp
-CMakeLists.txt
I have compiled the wxWidgets library using their cmake instructions for using a subdirectory in cmake so I could add it to my project. Here are the contents of the CMakeLists.txt's
ProjectName CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
set(MAJOR 0)
set(MINOR 0)
set(PATCH 1)
#Setup Project
project(ProjectNameProject VERSION ${MAJOR}.${MINOR}.${PATCH}
DESCRIPTION "ProjectName Descrip"
LANGUAGES CXX)
add_executable(ProjectName WIN32 ${PROJECT_SOURCE_DIR}/source/ProjectName.cpp
${PROJECT_SOURCE_DIR}/source/ui/MainWindow.cpp)
target_include_directories(ProjectName PRIVATE ${PROJECT_SOURCE_DIR}/source)
target_include_directories(ProjectName PRIVATE ${PROJECT_SOURCE_DIR}/source/ui)
target_link_libraries(ProjectName PRIVATE wx::net wx::core wx::base)
add_subdirectory(${CMAKE_SOURCE_DIR}/external)
ProjectName/externals CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
add_subdirectory(${CMAKE_SOURCE_DIR}/external/wxWidgets-3.1.6)
Update
I changed the Cmake option for building a shared library (DLL) and set it to OFF. When this is done, it builds a static library (LIB). This seemed to fix my linking issues.
Per Igor's suggestion, I took another look at the minimal sample CMakeLists.txt and noticed they used the following line for linking
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
Perhaps my line (below) is the way to link statically and does not work with DLLs?
target_link_libraries(ProjectName PRIVATE wx::net wx::core wx::base)
If someone could help me understand why having it build statically fixed it, I would 100% accept that answer.
I changed the Cmake option for building a shared library (DLL) and set it to OFF. When this is done, it builds a static library (LIB). This seemed to fix my linking issues.
Unfortunately I do no see anyone able to chime in to help understand why this is the solution, but I am going to select this as an answer for others coming to this in the future.
If I see any updates that answer the question of "why" I will accept their answer.
Now, I tried to build release mode from C++ source code with OpenCV.
This source code is built on debug mode, but it is not built on release mode.
The below images are my OpenCV library setting.
Please give me your help
1>------ Build started: Project: OpenCVServer, Configuration: Release x64 ------
1>StreamServer.obj : error LNK2001: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow#cv##YAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEBV_InputArray#1##Z)
1>StreamServer.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl cv::VideoCapture::read(class cv::_OutputArray const &)" (?read#VideoCapture#cv##UEAA_NAEBV_OutputArray#2##Z)
1>C:\workspace\OpenCVStream\OpenCVServer\x64\Release\OpenCVServer.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "OpenCVServer.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The error is most probably happening because you provided OpenCV library named ...d.lib to your release linker configuration.
d suffix in library file name means that it is debug library. All .lib files are usually shipped as two files, one for release (without d) and one for debug (with d).
Try to find release .lib and place it into your linker configuration.
83
Back-ends: imgui_impl_dx9.cpp + imgui_impl_win32.cpp
Operating System: Windows 10
Compiler: Visual Studio 2019
My Issue/Question:
I keep getting constant linker errors when trying to compile my program and I cannot figure out what is causing them
I have the files required and they're included in the .sln properties and in my main.cpp
1>------ Build started: Project: ConsoleApplication2, Configuration: Debug Win32 ------
1>ConsoleApplication2.cpp
1>imgui_widgets.cpp
1>Generating Code...
1>ConsoleApplication2.obj : error LNK2019: unresolved external symbol _Direct3DCreate9#4 referenced in function "bool __cdecl CreateDeviceD3D(struct HWND__ *)" (?CreateDeviceD3D##YA_NPAUHWND__###Z)
1>imgui_impl_win32.obj : error LNK2019: unresolved external symbol _XInputGetState#8 referenced in function "void __cdecl ImGui_ImplWin32_UpdateGamepads(void)" (?ImGui_ImplWin32_UpdateGamepads##YAXXZ)
1>imgui_impl_win32.obj : error LNK2019: unresolved external symbol _XInputGetCapabilities#12 referenced in function "void __cdecl ImGui_ImplWin32_UpdateGamepads(void)" (?ImGui_ImplWin32_UpdateGamepads##YAXXZ)
1>C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x64\xinput.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
1>C:\Users\Logan\source\repos\ConsoleApplication2\Debug\ConsoleApplication2.exe : fatal error LNK1120: 3 unresolved externals
1>Done building project "ConsoleApplication2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have a problem while compiling CGAL
I followed the steps here :
http://www.cse.msu.edu/~ytong/CGAL_installation.ppt
but when I reach at building CGAL .sln step
it show the following errors:
here
output:
1>------ Build started: Project: CGAL, Configuration: Debug Win32 ------
1> Building Custom Rule C:/dev/CGAL-4.9.1/src/CGAL/CMakeLists.txt
1> CMake does not need to re-run because C:\dev\CGAL-4.9.1\build\src\CGAL\CMakeFiles\generate.stamp is up-to-date.
1> all_files.cpp
1> Creating library C:/dev/CGAL-4.9.1/build/lib/Debug/CGAL-vc120-mt-gd-4.9.1.lib and object C:/dev/CGAL-4.9.1/build/lib/Debug/CGAL-vc120-mt-gd-4.9.1.exp
1>all_files.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::system_category(void)" (__imp_?system_category#system#boost##YAABVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat#system#boost##YAXXZ)
1>all_files.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (__imp_?generic_category#system#boost##YAABVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'errno_ecat''(void)" (??__Eerrno_ecat#system#boost##YAXXZ)
1>C:\dev\CGAL-4.9.1\build\bin\Debug\CGAL-vc120-mt-gd-4.9.1.dll : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
We are currently at CGAL 4.12 so please upgrade and follow official installation instructions.
I've been having problems with cmake and Visual Studio 2013 with SFML. When I try and compile my program, I'm getting unresolved externals for everything that uses SFML. I've had problems with this on multiple machines, and also with some other libraries in some case.
I'm using the following command to generate my Visual Studio Project (inside a VisualStudioProject folder):
Z:/Coding/cmake/cmake-3.1.1-win32-x86/bin/cmake.exe -G "Visual Studio 12" ..
And this is my CMakeLists.txt (it's actually generated from a python script I wrote, but I doubt that's important). I can confirm that all the libraries are being found correctly.
cmake_minimum_required (VERSION 2.6)
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/lib )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/lib )
project(Game)
include_directories( Z:/Coding/Libraries/SFML/SFML-2.2/include Z:/Coding/Game/src/win32 Z:/Coding/Game/src )
find_library( SFML-GRAPHICS NAMES sfml-graphics PATHS Z:/Coding/Libraries/SFML/SFML-2.2/lib NO_DEFAULT_PATH )
find_library( SFML-WINDOW NAMES sfml-window PATHS Z:/Coding/Libraries/SFML/SFML-2.2/lib NO_DEFAULT_PATH )
find_library( SFML-SYSTEM NAMES sfml-system PATHS Z:/Coding/Libraries/SFML/SFML-2.2/lib NO_DEFAULT_PATH )
add_executable( win32 "Z:/Coding/Game/apps/win32.cpp" )
target_link_libraries( win32 ${SFML-GRAPHICS} ${SFML-WINDOW} ${SFML-SYSTEM} )
This is my simple SFML test program:
#include <string>
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
int main(int argc, char *argv[])
{
sf::RenderWindow window;
window.create(sf::VideoMode(1280, 1024), "Test");
while (true)
{
sf::Event ev;
while (window.pollEvent(ev))
{
if (ev.type = sf::Event::EventType::Closed)
{
window.close();
exit(1);
}
}
}
std::string hello = "Hello";
cout << hello << endl;
}
And I'm getting unresolved externals for the following:
Error 1 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall sf::String::String(char
const *,class std::locale const &)"
(__imp_??0String#sf##QAE#PBDABVlocale#std###Z) referenced in function
_main Z:\Coding\Game\VisualStudioProject\win32.obj win32
Error 2 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall sf::String::~String(void)"
(__imp_??1String#sf##QAE#XZ) referenced in function
_main Z:\Coding\Game\VisualStudioProject\win32.obj win32
Error 3 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall
sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)"
(__imp_??0VideoMode#sf##QAE#III#Z) referenced in function
_main Z:\Coding\Game\VisualStudioProject\win32.obj win32
Error 4 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: void __thiscall
sf::Window::create(class sf::VideoMode,class sf::String const
&,unsigned int,struct sf::ContextSettings const &)"
(__imp_?create#Window#sf##QAEXVVideoMode#2#ABVString#2#IABUContextSettings#2##Z)
referenced in function
_main Z:\Coding\Game\VisualStudioProject\win32.obj win32
Error 5 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: void __thiscall
sf::Window::close(void)" (__imp_?close#Window#sf##QAEXXZ) referenced
in function _main Z:\Coding\Game\VisualStudioProject\win32.obj win32
Error 6 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: bool __thiscall
sf::Window::pollEvent(class sf::Event &)"
(__imp_?pollEvent#Window#sf##QAE_NAAVEvent#2##Z) referenced in
function _main Z:\Coding\Game\VisualStudioProject\win32.obj win32
Error 7 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall
sf::RenderWindow::RenderWindow(void)"
(__imp_??0RenderWindow#sf##QAE#XZ) referenced in function
_main Z:\Coding\Game\VisualStudioProject\win32.obj win32
Error 8 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: virtual __thiscall
sf::RenderWindow::~RenderWindow(void)"
(__imp_??1RenderWindow#sf##UAE#XZ) referenced in function
_main Z:\Coding\Game\VisualStudioProject\win32.obj win32
Error 9 error LNK1120: 8 unresolved
externals Z:\Coding\Game\bin\Debug\win32.exe win32
I've used this same style of script before with SFML in the past on Windows with an earlier VS successfully (at least I recall I have) so I think it's a new thing with VS 2013, but I'm utterly stumped.
Thanks in advance.
Note: This is a simplistic example. This style of CMakeLists.txt is generated by script because the main code-base it's used on is very large (originally Linux based, hence why '/'s are used everywhere).
This certainly looks like you've not actually linked any of the three SFML libs successfully.
If the find_library calls in the CMakeLists.txt had failed to find the libraries, then CMake would output a fatal error which I'm sure you'd have mentioned.
So my best guess is that you're trying to link the 64-bit version of the SFML libs, while your CMake command specifies a 32-bit build.
To create a 64-bit build, just run:
cmake -G "Visual Studio 12 Win64" ..
You'll need to empty your build folder to change the generator from "Visual Studio 12" to "Visual Studio 12 Win64".
See the docs for further info about the VS generator.
Stab in the dark:
Try running
Z:/Coding/cmake/cmake-3.1.1-win32-x86/bin/cmake.exe -G "Visual Studio 12 2013 Win64"
This will force it to do all the linking in a 64-bit environment. I am presuming you're using a 64-bit computer. I'm further presuming you have a 64-bit version of SFML. (It's the future, I think these are safe assumptions).
CMake will try and pick a "sensible" default as per http://www.cmake.org/cmake/help/v3.0/generator/Visual%20Studio%2012%202013.html but sometimes you want to force it to pick the right option.