I tried to build my app that uses glib-2.0 with Visual Studio.
The glib-2.0 was installed with pacman from msys2, so I haven't got glib-2.0.lib but I have glib-2.0.a
When I set glib-2.0.a and intl.a in Additional Dependencies from Visual Studio 2013, I got this errors:
Erreur 2 error LNK2001: symbole externe non résolu ___chkstk_ms C:\Users\julien\Documents\Visual Studio 2013\Projects\m\m\libintl.a(loadmsgcat.o) m
Erreur 66 error LNK2001: symbole externe non résolu __imp_getsockopt C:\Users\julien\Documents\Visual Studio 2013\Projects\m\m\libglib-2.0.a(giowin32.o) m
etc etc ...
I have set intl.a too because pkg-config --libs glib-2.0 --msvc-syntax returns:
/libpath:C:/msys64/mingw64/lib.lib glib-2.0.lib intl.lib
What I have to do to build my app?
You need to build GLIB with MSVC.
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.
I'm compiling HTTPD 2.4.48 along with Lua, Zlib, cURL, jansson and OpenSSL.
Here is the list of files and software I use:
httpd-2.4.48
apr-1.7.0
apr-util-1.6.1
cURL 7.77.0
expat-2.4.1
jansson 2.13.1
Lua 5.4.3
mod_fcgid 2.3.9
openssl-1.1.1k
pcre-8.44
ZLIB 1.2.11
ActivePerl v5.28.1.2801 (x64)
CMake v3.20.3 (x64)
NASM v2.15.05 (x64)
Gawk v3.1.6-1 (x86)
The whole compile statement I use:
Visual Studio 2015: call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
*****************
** ZLIB Build **
*****************
cd /D C:\httpd\srclib\zlib\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
nmake
nmake install
****************
** Pcre Build **
****************
cd /D C:\httpd\srclib\pcre\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_BUILD_TESTS=OFF -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_SUPPORT_PCREGREP_JIT=OFF -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON -DPCRE_NEWLINE=CRLF -DINSTALL_MSVC_PDB=OFF ..
nmake
nmake install
*****************
** Expat Build **
*****************
cd /D C:\httpd\srclib\expat\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
nmake
nmake install
*******************
** OpenSSL Build **
*******************
cd /D C:\httpd\srclib\openssl
perl Configure VC-WIN64A --release --prefix=\phpStudy\Apache --openssldir=\phpStudy\Apache\conf enable-camellia no-idea no-mdc2 no-ssl2 no-ssl3
nmake
nmake install
***************
** Lua Build **
***************
cd /D C:\httpd\srclib\lua\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release ..
nmake
nmake install
****************
** cURL Build **
****************
cd /D C:\httpd\srclib\curl\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
nmake
nmake install
*******************
** jansson Build **
*******************
cd /D C:\httpd\srclib\jansson\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
nmake
nmake install
***************
** APR Build **
***************
cd /D C:\httpd\srclib\apr\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMIN_WINDOWS_VER=0x0600 -DAPR_HAVE_IPV6=ON -DAPR_INSTALL_PRIVATE_H=ON -DAPR_BUILD_TESTAPR=OFF -DINSTALL_PDB=OFF ..
nmake
nmake install
********************
** APR-Util Build **
********************
cd /D C:\httpd\srclib\apr-util\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DOPENSSL_ROOT_DIR=\phpStudy\Apache -DAPU_HAVE_CRYPTO=ON -DAPR_BUILD_TESTAPR=OFF -DINSTALL_PDB=OFF ..
nmake
nmake install
******************
** Apache Build **
******************
cd /D C:\httpd\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DENABLE_MODULES=i -DINSTALL_PDB=OFF ..
nmake
nmake install
Everything worked almost perfectly, however in the last step when I compile HTTPD I got the error:
[ 44%] Linking C shared library mod_md.so
LINK: command "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe /nologo #CMakeFiles\mod_md.dir\objects1.rsp /out:mod_md.so /implib:mod_md.lib /pdb:C:\httpd\bin\mod_md.pdb /dll /version:0.0 /base:#C:/httpd/bin/BaseAddr.ref,mod_md.so /machine:x64 /INCREMENTAL:NO \phpStudy\Apache\lib\libssl.lib \phpStudy\Apache\lib\libcrypto.lib \phpStudy\Apache\lib\jansson.lib mod_watchdog.lib libhttpd.lib \phpStudy\Apache\lib\libapr-1.lib \phpStudy\Apache\lib\libaprutil-1.lib \phpStudy\Apache\lib\apr_ldap-1.lib ws2_32.lib mswsock.lib \phpStudy\Apache\lib\pcre.lib ws2_32.lib mswsock.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:mod_md.so.manifest" failed (exit code 1120) with the following output:
Creating library mod_md.lib and object mod_md.exp
md_curl.c.obj : error LNK2019: unresolved external symbol curl_global_init referenced in function md_curl_init
md_curl.c.obj : error LNK2019: unresolved external symbol curl_slist_append referenced in function curlify_headers
md_curl.c.obj : error LNK2019: unresolved external symbol curl_slist_free_all referenced in function md_curl_req_cleanup
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_strerror referenced in function md_curl_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_init referenced in function internals_setup
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_setopt referenced in function internals_setup
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_perform referenced in function md_curl_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_cleanup referenced in function md_curl_req_cleanup
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_getinfo referenced in function md_curl_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_init referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_add_handlereferenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_remove_handle referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_wait referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_perform referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_cleanup referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_info_read referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_strerror referenced in function md_curl_multi_perform
mod_md.so : fatal error LNK1120: 17 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
I found out the answer of this question: Visual Studio 2015 curl will not statically link
Change the code of the md_curl.c file to:
#pragma comment(lib, "wldap32.lib" )
#pragma comment(lib, "crypt32.lib" )
#pragma comment(lib, "Ws2_32.lib")
#define CURL_STATICLIB
#include <curl/curl.h>
But this error still occurs.
Where did I go wrong? I'm getting confused because this is the first time I've encountered this error when compiling HTTPD.
Your answer will be very helpful. I would appreciate that!
Whenever you fix issues, start by the first one (cause solving that may remove the remaining), which in you case seems to be:
error LNK2019: unresolved external symbol curl_global_init referenced in function md_curl_init
And it basically is telling us that, the md_curl_init method calls curl_global_init method, but while compile-time declaration was available, the linker-time required definition is missing.
Anyway, to fix this ensure curl is added as a library, I mean, is currently not in your linker command-line (not in what you posted at least).
Edit I will suggest you approaches, for how you can do that.
But first, giving it more time, I see that:
Yes, you already compile curl.
Your "whole compile statement" thing is using C:\httpd\srclib\curl\bin as build-directory for cURL.
Also, you should be able to find curl.lib in C:\httpd\srclib\curl\bin directory (which was used as build-directory).
Approach #1:
Create a root CMakeFiles.txt file and add your other projects with add_subdirectory(...) method.
I recommend this approach, as CMake will handle for you the task of finding curl automatically.
I mean, you just would need to do something like:
target_link_libraries(myTargetThatNeedsCurl
curl
)
Approach #2:
If you don't want to change "whole compile statement" thing, then your only choice may be to place curl.lib somewhere that your other build-script can find it (manually or through some custom install(...) method calls, I leave that to you).
Approach #3:
First, edit httpd project (the C:\httpd\CMakeFiles.txt file), and add add_subdirectory(srclib/curl) somewhere in beginning.
Then, find cURL target's name, like, open the C:\httpd\srclib\curl\CMakeFiles.txt file and see all add_library(...) call's first argument (one of them is what we want).
Finally, edit httpd project again, but now add what you found in step-2 as argument to target_link_libraries(...) method.
Note that Approach #3 is same as #2, but just for cURL (instead of adding all sub-directories).
I try to use dlib in Qt project on Windows. After downloading I at once started to try build my Qt application, without building examples. I also downloaded static libraries libpng and libjpeg from GnuWin.
.pro file:
SOURCES += main.cpp\
mainwindow.cpp \
C:/Users/user/Downloads/dlib-19.0/dlib-19.0/dlib/all/source.cpp
HEADERS += mainwindow.h
INCLUDEPATH += "C:\Users\user\Downloads\dlib-19.0\dlib-19.0"
LIBS += -L"C:\Users\user\Downloads\dlib-19.0\dlib-19.0"
INCLUDEPATH += "C:\Users\user\Downloads\dlib-19.0\dlib-19.0\dlib\external\libpng"
INCLUDEPATH += "C:\Users\user\Downloads\dlib-19.0\dlib-19.0\dlib\external\libjpeg"
LIBS += -L"C:\Users\user\Downloads\jpeg-6b-4-lib\lib" -ljpeg
LIBS += -L"C:\Users\user\Downloads\libpng-1.2.37-lib\lib" -lpng
LIBS += -lwinmm -lws2_32 -luser32 -lgdi32 -lcomctl32 -limm32
QMAKE_CXXFLAGS += -std=c++11 -DDLIB_PNG_SUPPORT -DDLIB_JPEG_SUPPORT
Code:
try
{
array2d<rgb_pixel> img;
load_image(img, "C:\\Users\\user\\Downloads\\test.jpg");
}
catch (exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
}
MinGW output:
png_loader.cpp:103: undefined reference to 'png_set_longjmp_fn'
png_loader.cpp:153: undefined reference to 'png_set_longjmp_fn'
save_png.cpp:20: undefined reference to 'png_set_longjmp_fn'
save_png.cpp:72: undefined reference to 'png_set_longjmp_fn'
I know that I need to use libpng 1.4, but I can't find this version in GnuWin, so I used the most relevant 1.2.
MSVC runtime exception:
exception thrown!
Unable to load image in file C:\Users\user\Downloads\test.jpg.
You must #define DLIB_JPEG_SUPPORT and link to libjpeg to read JPEG
files.
Do this by following the instructions at http://dlib.net/compile.html.
Note that you must cause DLIB_JPEG_SUPPORT to be defined for your
entire project.
So don't #define it in one file. Instead, add it to the
C/C++->Preprocessor->Preprocessor Definitions
field in Visual Studio's Property Pages window so it takes effect for
your entire application.
But I set -DDLIB_JPEG_SUPPORT in my .pro file, linked with jpeg and png and even downloaded in the working folder shared library jpeg.dll.
How can I solve this probles or how can I use dlib in Qt on Windows?
UPD:
Errors after E:\CMake\bin\cmake.exe --build . --config Release:
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\3d_point_cloud_ex.vcxproj" (default target)
(3) ->
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj" (default target) (4
) ->
(target ClCompile) ->
f:\gstreamer\1.0\x86\include\jmorecfg.h(211): error C2371: 'boolean': redefinition; different basic types [C:\Users\user
\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
C:\Program Files (x86)\Windows Kits\8.1\Include\shared\basetsd.h(72): error C2371: 'INT32': redefinition; different b
asic types [C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
c:\program files (x86)\windows kits\8.1\include\shared\rpcndr.h(178): error C2371: 'boolean': redefinition; different
basic types [C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
c:\program files (x86)\windows kits\8.1\include\shared\wtypesbase.h(493): error C2371: 'BOOLEAN': redefinition; diffe
rent basic types [C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
UPD2:
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\3d_point_cloud_ex.vcxproj" (default target) (3) ->
"C:\Users\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj" (default target) (4) ->
(target ClCompile) ->
C:\Users\user\Downloads\dlib-19.0\dlib-19.0\dlib\image_loader\jpeg_loader.cpp(17): fatal error C1083: Cannot open include file: 'jpeglib.h': No such file or directory [C:\U
sers\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
C:\Users\user\Downloads\dlib-19.0\dlib-19.0\dlib\image_saver\save_jpeg.cpp(16): fatal error C1083: Cannot open include file: 'jpeglib.h': No such file or directory [C:\User
s\user\Downloads\dlib-19.0\dlib-19.0\examples\build\dlib_build\dlib.vcxproj]
UPD3:
.pro file:
INCLUDEPATH += "E:\dlib_build\include"
LIBS += -L"E:\dlib_build"
LIBS += -ldlib
QMAKE_CXXFLAGS_RELEASE += /arch:AVX
QMAKE_CXXFLAGS += -std=c++11 -DDLIB_PNG_SUPPORT -DDLIB_JPEG_SUPPORT
MSVC 2015 64bit Release output:
mainwindow.obj : error LNK2019: unresolved external symbol "public: __cdecl dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2(void)" (??0entrop...
mainwindow.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2(void)" (...
mainwindow.obj : error LNK2019: unresolved external symbol "public: void __cdecl dlib::entropy_decoder_kernel_2::set_stream(class std::basic_istream<c...
mainwindow.obj : error LNK2019: unresolved external symbol "public: void __cdecl dlib::entropy_decoder_kernel_2::decode(unsigned int,unsigned int)" (?...
mainwindow.obj : error LNK2019: unresolved external symbol "public: unsigned int __cdecl dlib::entropy_decoder_kernel_2::get_target(unsigned int)" (?g...
mainwindow.obj : error LNK2019: unresolved external symbol "public: __cdecl dlib::png_loader::png_loader(class std::basic_string<char,struct std::char...
mainwindow.obj : error LNK2019: unresolved external symbol "public: __cdecl dlib::png_loader::~png_loader(void)" (??1png_loader#dlib##QEAA#XZ) referen...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::png_loader::is_gray(void)const " (?is_gray#png_loader#dlib##QEB...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::png_loader::is_graya(void)const " (?is_graya#png_loader#dlib##Q...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::png_loader::is_rgb(void)const " (?is_rgb#png_loader#dlib##QEBA_...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::png_loader::is_rgba(void)const " (?is_rgba#png_loader#dlib##QEB...
mainwindow.obj : error LNK2019: unresolved external symbol "private: unsigned char const * __cdecl dlib::png_loader::get_row(unsigned int)const " (?ge...
mainwindow.obj : error LNK2019: unresolved external symbol "public: __cdecl dlib::jpeg_loader::jpeg_loader(class std::basic_string<char,struct std::ch...
mainwindow.obj : error LNK2019: unresolved external symbol "public: bool __cdecl dlib::jpeg_loader::is_gray(void)const " (?is_gray#jpeg_loader#dlib##Q...
mainwindow.obj : error LNK2019: unresolved external symbol USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSER...
E:\dlib_build\lib\dlib.lib : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
release\dlibWindows.exe : fatal error LNK1120: 15 unresolved externals
jom: F:\Projects\QtProjects\build-dlibWindows-Desktop_Qt_5_6_0_MSVC2015_64bit-Release\Makefile.Release [release\dlibWindows.exe] Error 1120
UPD4:
.pro file:
INCLUDEPATH += "E:\dlib_build\include"
LIBS += -L"E:\dlib_build"
LIBS += -ldlib
QMAKE_CXXFLAGS_RELEASE += /arch:AVX
Code:
try
{
//or even just one line "frontal_face_detector detector = get_frontal_face_detector();"
array2d<rgb_pixel> img;
load_image(img, "C:/Users/user/Downloads/test.jpg");
}
catch (exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
}
Release output:
Exited with code 255
You have chosen the way of compiling by incliding all/source.cpp into your project. This is possible but I think not the best way how to use dlib.
So if you want to use all/source.cpp in your project - please follow instructions from here: http://dlib.net/compile.html
Compiling on Windows Using Visual Studio
All you need to do is create an empty console project. Then add dlib/all/source.cpp to it and add the folder containing the dlib folder to the #include search path. Then you can compile any example program by adding it to your project.
Again, note that dlib will only be able to work with jpeg and png files if you link in libjpeg and libpng. In Visual Studio, the easiest way to do this is to add all the source files in the dlib/external folder into your project and also define the DLIB_PNG_SUPPORT and DLIB_JPEG_SUPPORT preprocessor directives. If you don't know how to configure Visual Studio then you should use CMake as shown above since it will take care of everything automatically.
And with adding dlib/external folder - you can remove libjpeg and libpng from your project.
But as I said - its not the best way how to compile dlib. Dlib is designed to be used with CMAKE and the best way is to build it with CMAKE.
Why this way is better:
no need to rebuild dlib every time your project changes
possible use of CUDA code (not now - but a bit later when CUDA 8 and VS update 4 will be released)
Here the first step (after installing CMAKE) should be checking if Dlib works. According to Dlib's instructions best way is to build examples and run them (from dlib's folder):
cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release
When running cmake .. you can specify your compiler version, for example:
cmake .. -G"Visual Studio 14 2015 Win64"
To build examples with Visual Studio 2015 x64
After testing examples its a good time to build Dlib and start using it in real projects. And yes, again build is done by CMAKE (from dlib folder):
mkdir build
cd build
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=C:\Users\user\dlib
cmake --build . --config Release --target install
The building process is little different from building examples:
CMAKE_INSTALL_PREFIX=C:\Users\user\dlib - compiled dlib will be installed into C:\Users\user\dlib
--target install means we are installing dlib
After the building process will be finished - you are free to use dlib.lib (static version of Dlib) from C:\Users\user\dlib\lib. If you will use CMAKE with your project - you will need to add -DCMAKE_PREFIX_PATH=c:\Users\user\dlib. But now you are trying to compile with Qt Creator (QMake). Here is your .pro file should look like (the minimal possible example):
SOURCES += face_detection_ex.cpp
INCLUDEPATH += "C:\Users\user\dlib\include"
LIBS += -L"C:\Users\user\dlib"
LIBS += -ldlib
QMAKE_CXXFLAGS_RELEASE += /arch:AVX
This project will not compile and run in Debug mode build because we used --config Release in our building process. But Release mode will run very fast
Please note
Visual Studio will need separate dlib installation for Release and Debug builds. And Debug build of Dlib will be extremely slow
Adding /arch:AVX to compiler flags (MSVC) will make Dlib run much faster
DNN module will not work under MSVC until Cuda 8 and MSVC 2015 update 4 will be released
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.
I'm trying to write some C++ code for Windows 7 which will connect to a mobile broadband network. When I run the first example at http://msdn.microsoft.com/en-us/library/ee677092(v=VS.85).aspx I get the following when compiling within Visual Studio:
testII.obj : error LNK2001: unresolved external symbol _CLSID_MbnInterfaceManager
testII.obj : error LNK2001: unresolved external symbol _IID_IMbnInterfaceManager
or when I compile with the "cl" command at the command prompt I get:
test.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
test.obj : error LNK2019: unresolved external symbol _CLSID_MbnInterfaceManager referenced in function _main
test.obj : error LNK2019: unresolved external symbol _IID_IMbnInterfaceManager referenced in function _main
test.exe : fatal error LNK1120: 2 unresolved externals
It would seem I need to link so some library somewhere, can anyone tell me which library and how to link it? Do these errors have anything to do with the mbnapi.idl requirement?
Thanks a lot, appreciate it
What you need to do is include mbnapi_uuid.lib