dlib static lib error in debug mode - c++

I'm currently trying dlib 19.1 for a project.
I build all the example using cmake, and I also build dlib with VS 2013 to obtain the static lib. So I have my Install folder where the dlib are created. I compile in Release and also in Debug using the same .sln created with the cmake. So until now, no problem.
Next to that, I went in my project (a console project), and I pointed to header and lib (release and debug). Note that this project only contain a Main.cpp that call different function from my own other project libs and that main also call the face landmarks detection from dlib.
So, I have no issue to compile my project in Release with the dlib.lib that I created. But when using the debug dlib.lib and try to launch my own project in debug mode, I obtain the following error :
error LNK2001: unresolved external symbol
_USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_
Is there anything done wrong ? When I'm looking to my preprocessor in cmake .sln in debug I have the _DEBUG and also in my own project.

The possible solution is to build dlib not from .sln files, but directly by cmake:
mkdir build
cd build
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=c:\prj\dlib_build_release
cmake --build . --target install --config Release
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=c:\prj\dlib_build_debug
cmake --build . --target install --config Debug
This will compile and install dlib binaries and headers into c:\prj\dlib_build_release and c:\prj\dlib_build_debug directories
After that you can use dlib compiled library from this directories

Related

CMake Error Failed to run MSBuild command

I am very new to CMake and try to build a minimum CMake file on Windows where I have installed Visual Studio 17 and 19. The C++ code is the bare minimum main.cpp:
#include<iostream>
int main()
{
std::cout << "Hello" << std::endl;
return 0;
}
The CMakeLists.txt file is also the minimum:
cmake_minimum_required(VERSION 3.1)
project(hello)
add_executable(${PROJECT_NAME} main.cpp)
When I run the CMake on the command line, I get this error and I do not know how to resolve it:
C:\SampleProject\build>cmake ./../src
-- Building for: Visual Studio 15 2017
CMake Error at CMakeLists.txt:3 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
The system cannot find the file specified
By default VC++ tools aren't on the PATH, they are added to the PATH by the vcvarsall.bat script.
Run cmake from a "x64 Native Tools Command Prompt for VS 2019" (it's a shortcut to vcvarsall.bat that Visual Studio installs in the Start Menu).
Bonus note:
When not using Visual Studio integration, you might want to consider Ninja as the alternative build system to MSBuild. It's more CMake-friendly because it doesn't require the Debug/Release duality of configuration (which is the source of headache when working with CMake).
Download ninja.exe, add it to the PATH
Use the Ninja CMake generator: cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ..
Enjoy easy and fast builds using the ninja command.
To build a Release version, re-run cmake with -DCMAKE_BUILD_TYPE=Release (so this works very much the same as on other platforms, e.g. Linux).
Ninja also integrates well with the VSCode CMake extension (note: VSCode != VS).

Cannot compile GLFW after building it in QtCreator with CMake (Ubuntu)

I have downloaded the GLFW source package for building the library.
In the QtCreator IDE, I go to File/Open file or project and select the CMakeLists.txt of GLFW. The project is built and the resulting files stored in a certain folder.
The next step is to compile the library to get the .a files (we want to create a static library that could be used by another application). However, the compilation never ends, and the compile output shows "Persisting CMake state..." forever.
I have made my research but cannot find an answer to this. I'm not an expert on CMake or QtCreator IDE.
I could build the project for MVS (Microsoft Visual Studio) in Windows with cmake -G"Visual Studio 15 2017" path/to/CMakeLists.txt
And then compile the resulting MVS project with MVS.
I could do the same on Linux using only the command line (cmake path/to/CMakeLists.txt, make all).
However, I find these problem with QtCreator...

CMake doesn't generate vc pdb for simple test program

I am trying to use CMake on Windows 10. I create a Hello world project:
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
add_executable(simple-program main.cpp)
main.cpp
#include <iostream>
int main()
{
std::cout << "Hello, World!\n";
}
Then I open the project with CMake gui, choose Visual Studio 10 2010 Win64 generator and get this error when trying to generate the project:
testCCompiler.c : fatal error C1033: cannot open program database 'c:\work\prj\simple-program\build\cmakefiles\cmaketmp\cmtc_983e7.dir\debug\vc100.pdb'
Full output.
As I understood the problem, due to Zi option and no Fd, which cmake sets for the sample project, the project is trying to find vc100.pdb database and there is no one because the generator didn't make it.
I've tried the x86 generator. Other cmake versions (3.6, 3.13, 3.12). And I get the same result when using the console. My VS 2010 should be ok - it generates the PDB when I create the project from it.
Thank you!
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1033?view=vs-2017
Fatal Error C1033
This error can be caused by a disk error, a temporary lock created by an anti-virus program, a previous debugger instance that has not fully shut down, or parallel build mspdbsrv.exe processes that attempt to access the same file, among other possible causes.
NOTE:
I couldn't find the error codes for VS2010 on the Microsoft website. I don't think VS2010 is supported anymore and may not make working programs on Windows 10.
The problem was because I created build folder in WSL console. So it can be caused by any kind emulators like Cygwin, etc. Hope it will help someone.
Just build your generated project in Debug mode:
MSBuild ALL_BUILD.vcxproj /p:Configuration=Debug
If you want to create a Release and install it with PDB files just all:
list(APPEND INSTALL_TARGETS simple-program)
list(APPEND INSTALL_TARGETS_PDB simple-program)
# Install
install(TARGETS ${INSTALL_TARGETS}
RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin"
LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/bin"
ARCHIVE DESTINATION "${PROJECT_SOURCE_DIR}/bin")
# Install *.pdb files
if(MSVC)
foreach(INSTALL_TARGET_PDB ${INSTALL_TARGETS_PDB})
install(FILES $<TARGET_PDB_FILE:${INSTALL_TARGET_PDB}> DESTINATION "${PROJECT_SOURCE_DIR}/bin")
endforeach()
endif()
Finall run CMake and build in RelWithDebInfo mode:
cmake -G "Visual Studio 10 2010 Win64"
MSBuild ALL_BUILD.vcxproj /p:Configuration=RelWithDebInfo
MSBuild INSTALL.vcxproj /p:Configuration=RelWithDebInfo
This will create simple-program.exe and simple-program.pdb files in your install dir.

cmake incremental build with vs 2015 and llvm-vs2014 toolset

When i use VS 2015 with llvm-vs2014 toolset on my project (project generated by cmake 3.9) the incremental build is not available: if i restart build or modify only one cpp file, the whole solution is built and it takes time...
In this case, incremental build is not available in VS2015 ? How can i activate it.
An example of my toolchain commands:
cmake -G"Visual Studio 14 2015" -T"LLVM-vs2014" myBuild
msbuild myBuild.sln /t:myPrpoject /maxcpucpunt
I tried to modify msbuild parameters but nothing happen

libzip with Visual Studio 2010

How can I compile libzip for Visual Studio 2010?
Edit:
Before starting on the answer provided here, it appears that this may no longer be an issue going by #Thomas Klausner's answer below.
The following should get you a VS10 solution:
If you've not already done so, install CMake
Download and extract zlib to e.g. C:\devel. The download links are about halfway down the homepage. Currently this provides zlib version 1.2.7.
To work around this CMake bug which affects 64-bit Windows only, add
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MSVC)
set_target_properties(zlibstatic PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
endif()
to the end of C:\devel\zlib-1.2.7\CMakeLists.txt
Download and extract libzip to e.g. C:\devel
In a VS10 command prompt, cd C:\devel\zlib-1.2.7
mkdir build && cd build
cmake .. -G"Visual Studio 10" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib" This sets the install path to C:\devel\installed\zlib rather than the default C:\Program Files\zlib. For 64-bit Windows, use "Visual Studio 10 Win64" as the -G parameter.
msbuild /P:Configuration=Debug INSTALL.vcxproj
msbuild /P:Configuration=Release INSTALL.vcxproj
cd C:\devel\libzip-0.10.1
mkdir build && cd build
cmake .. -G"Visual Studio 10" -DCMAKE_PREFIX_PATH="C:\devel\installed\zlib" Set the path to wherever you installed zlib so that CMake can find zlib's include files and libs. Again, for 64-bit Windows, use "Visual Studio 10 Win64" as the -G parameter.
This should result in C:\devel\libzip-0.10.1\build\libzip.sln. It looks like there are a few POSIX-specific problems in the code, but they should hopefully be fairly easy to resolve (e.g. in zipconf.h #include <inttypes.h> needs replaced with #include <stdint.h>; there are some snprintf calls needing replaced e.g. with _snprintf).
I can't comment, so just in addition to Fraser's answer: In the last days, libzip's latest repository version should compile on VS without additional patches. Please try it out and let the developers know if parts are still missing.
Can't comment on answer above but was trying to get this to work and in the end found that the Output directory under the configuration properties and the comand in debugging.
You can remove ALL_BUILD, ZERO_CHECK, INSTALL and PACKAGE and it will build fine without any of the linking errors or linux specific errors.
Using libzip-1.0.1, zlib-1.2.8, and VS Community 2013.
Added to path:
C:\Program Files (x86)\CMake\bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319
The cmake line became:
cmake .. -G"Visual Studio 12 Win64" -DCMAKE_INSTALL_PREFIX="C:\devel\installed\zlib"
devel\libzip-1.0.1\lib\zip_source_filep.c:189 changed:
mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
to:
mask = umask(_S_IREAD | _S_IWRITE);
Using
an environment variable %ZLIB_DIR% for the path to zlib-1.2.8,
%LIBZIP_DIR% for the path to libzip-1.0.1
VS 2015 Express Edition, and
the file %LIBZIP_DIR%/lib/zip_source_filep.c patched according to http://hg.nih.at/libzip/rev/80457805a1e7 ,
the process for building zlib and libzip becomes this:
Building zlib
> cd /d %ZLIB_DIR% && md build & cd build
> cmake .. -G"Visual Studio 14 2015 Win64"- DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%"
> msbuild /P:Configuration=Debug INSTALL.vcxproj
> msbuild /P:Configuration=Release INSTALL.vcxproj
Building libzip
> cd /d %LIBZIP_DIR% && md build & cd build
> cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH="%ZLIB_DIR%"
> msbuild /P:Configuration=Debug ALL_BUILD.vcxproj
> msbuild /P:Configuration=Release ALL_BUILD.vcxproj
Done!
(So you see, #MikeLischke, CMake does indeed work out-of-the-box sometimes...)
In current zlib version, there is a contrib for this:
zlib-1.2.8\contrib\vstudio\vc10\zlibvc.sln
I got an error on load because one of the configurations wasn't valid on my machine, but a recompile took care of that. I also had to change the project properties>Configuration Properties>Linker>Input>Additional Dependencies for the Debug configuration to change zlibwapi.lib to zlibwapid.lib.
In Visual Studio 2015, Win64:
If building libzip failing with a message like this:
Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.8").
All you have to do is copy the generated 'zlib.dll/zlibd.zll' and 'zlib.lib/zlibd.lib' to the top of the zlib directory (where the .h/.c files are).
The answer given by Christian Severin helped me a lot, but needed some updates for VS2019 and 32-bit:
When building with VS 2019, you must use the -A option, not use "Win64".
When building with VS 2019, the 32-bit archive is "Win32", not x86.
The "Building zlib" section has a typo, it must be Win64" -DCMAKE_..., with a space before the dash
Here is a working example with VS2019 and 32-bit build:
cd /d %ZLIB_DIR% && md build & cd build
cmake .. -G"Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%" -AWin32
msbuild /P:Configuration=Release INSTALL.vcxproj
cd /d %LIBZIP_DIR% && md build & cd build
cmake .. -G"Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%" -AWin32
msbuild /P:Configuration=Release ALL_BUILD.vcxproj