Adding OR-Tools Library to Visual Studio - c++

I am trying to write a code using Google's OR-Tools library on Microsoft Visual Studio 2019. I followed the following steps:
Installed OR-Tools from Binary on Windows on their website.
Extracted the .zip file in C:\Libraries
Wrote my code on VS (I wrote #include <ortools/linear_solver/linear_solver.h> and using namespace operations_research; rest is usual C++ Code)
In Visual Studio, went to Project > Properties > C/C++ > Additional Include Directories
Added "C:\Libraries\or-tools\include" (which contains the folder "ortools" that I included)
Clicked Apply then OK then compiled my code.
I am getting a bunch of linking errors "error LINK2019". Is there anything else I should do so I can use this library freely on my machine?

From the supplied makefile:
Compile flags:
DEBUG = /O2 -DNDEBUG
CXXFLAGS = /std:c++17 /EHsc /MD /nologo /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -nologo $(DEBUG) \
/DPSAPI_VERSION=1 /D__WIN32__ /DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS \
/DGFLAGS_DLL_DECL= /DGFLAGS_DLL_DECLARE_FLAG= /DGFLAGS_DLL_DEFINE_FLAG= /DGOOGLE_GLOG_DLL_DECL= \
/I$(INC_DIR)\\src\\windows /I$(INC_DIR) /I. \
/DUSE_BOP /DUSE_GLOP \
/DUSE_CBC /DUSE_CLP \
/DUSE_SCIP
Link flags:
LDFLAGS = psapi.lib ws2_32.lib
OR_TOOLS_LNK = lib\\ortools.lib

Related

NMAKE: How do I force a debug build? [7ZIP]

The suggested way of building 7Zip is on the command line via the nmake command line utility. 7zip doesn't seem to come with a working visual studio solution.
I have seen invocations such as nmake NEW_COMPILER=1 MY_STATIC_LINK=1 suggested for initiating a build using the various nested .MAK files.
Using this command line interface how might I force a build with debug symbols?
If there is no standard way to accomplish this via nmake, I'd be glad to receive help with regards to 7Zip in particular. I am much less familiar with .MAK than GNU make, and have thus far been unable to find something akin to a "debug target" in the GNU make sense in 7ZIP.
To make a project that uses visual studio nmake build a debug output you need to edit the makefile and make 2 changes.
First you need to add /Zi to the list of flags used when compiling
CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -W4 -WX -EHsc -Gy -GR- -GF /Zi
Second you need to add /debug to list of options for the linker e.g.
LFLAGS = $(LFLAGS) -nologo -OPT:REF -OPT:ICF /DEBUG
I tested this on a different library, I assume there will be similarities here.
7zip archiver gives great compression and performance results, but unfortunately have lack of documentation nor for building process nor at the entire code.
I know that the question asked 1.5 yrs ago but I hope to save someone time for digging around in the 7z.
To build 7z from sources you need the Microsoft Visual Studio and do following steps:
Start Tools Command Prompt for VS 2019
Navigate to sources folder cd c:\sources\7z
Invoke nmake /f makefile
Otherwise you can convert MSVC 6.0 dsw/dsp files to modern .vcxproj format. Just open dsw file in the MSVC 2019 and it will do the conversion automatically.
The trick is that you need to navigate into project directory to do that. The 7z build system hard tied to relative directory structure and gets build parameters from top level main Build.mak file.
So, if you need to modify build parameters for all projects it is enough to modify that file.
For 7z version 19.00 you need to edit these lines in CPP/Build.mak file:
Add /Zi fag to line CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -W4 -WX -EHsc -Gy -GR- -GF /Zi
Add /DEBUG LFLAGS = $(LFLAGS) -nologo -OPT:REF -OPT:ICF /DEBUG
Change -O1 and -O2 for flags CFLAGS_O1 CFLAGS_O2
!IF "$(PLATFORM)" == "x64"
CFLAGS_O1 = $(CFLAGS) -Od
!ELSE
CFLAGS_O1 = $(CFLAGS) -Od
!ENDIF
CFLAGS_O2 = $(CFLAGS) -Od

Clang 4.0 debugging using Visual Studio

I have a project that I am still trying to setup using Clang and Visual Studio on Windows. As a caveat, I've worked on several c++ projects but they've all been mature projects where I haven't had to be involved in setting up make files or resolving dependencies hence why I want some experience in doing so.
As a clarification, I am not using the LLVM built into visual studio thing. My goal was to have visual studio be a convenience on top of having a project that can be built with make files but not using CMake.
So far, I have a solution with a single nmake project. This nmake project calls a build.bat file which calls into a make file. This make file looks like this:
# Based on PUXAN tutorial
# http://www.puxan.com/web/howto-write-generic-makefiles/
# Compiler choice
CC = clang++ -g -O0
CC_OBJ_FLAGS = -w -v -c
# Name of our executable and also the main run target
EXEC = ../bin/output.exe
# Here we get every cpp file in the source directory to make a list of source files
SOURCES = $(wildcard ../src/*.cpp)
# Here we have mapped all the cpp files to o files and now have a list of o files
TMP_OBJECTS = $(SOURCES:.cpp=.o)
OBJECTS = $(foreach obj,$(TMP_OBJECTS),$(subst src,obj,$(obj)))
INC = -I../lib/glfw-3.2.1/include
LINK = -L../lib/glfw-3.2.1/lib-vc2015 -lglfw3dll -lglfw3 -lopengl32
# compile list of o files into executable
# NOTE: when make is run without a target, the first target is chosen. This target
# should remain the first at all times
$(EXEC): $(OBJECTS)
$(CC) $(LINK) $(OBJECTS) -o $(EXEC)
# As each o file becomes a target, compile the associated cpp file into the o file
../obj/%.o: ../src/%.cpp
$(CC) $(CC_OBJ_FLAGS) $(INC) $< -o $#
# Remove the entire list of objects and the executable
clean:
rm -f $(EXEC) $(OBJECTS)
rebuild:
make -B
You'll notice that I've included the -g and -O0 flags which should output symbols and sure enough, I get a pdb file generated for output.exe (and also all the o files but I can clean that up later). When I go to debug the project in Visual Studio however, it says the symbols for the module are loaded but breakpoints aren't hitting which I think is pointing to the pdb not having references to the source. Here is the debug output in Visual Studio:
'output.exe' (Win32): Loaded 'W:\Scratch\Engine\bin\output.exe'. Symbols loaded.
Posts about Clang from 2016 and earlier mention that it doesn't generate PDB files yet and that thats a work in progress and sure enough the Clang compability site (https://clang.llvm.org/docs/MSVCCompatibility.html) mentions how debug info is a work in progress but that I should be able to generate CodeView info using /Z with 7 or i. I have tried passing both /Zi and /Z7 to clang and to the linker directly but clang complains about them and the linker ignores them with a warning. This documentation claims to be from Clang 6 that is, from what I can tell, not released yet and is experimental. However, using Clang 4.0 with -g flag, I am indeed able to generate pdb files.
Does anyone have any further information on this? Is there anything else I can provide to determine if I have set all this up correctly? Am I just missing a flag that would correctly provide the sources or am I missing a setting in visual studio to pick the sources? I tried setting sources manually in visual studio at the project and solution level to no effect. Should I look at the pdb file with a pdb viewer of some kind and see if the source paths are there?
Thanks in advance to any help.
The clang option equivalent to -Z7/-Zi is called -gcodeview (and has to be used in addition to -g). For MSVC-style command line options, you need to use the clang-cl compiler driver instead.
For the MSVC Version ( https://llvm.org/builds/) it works like in the following picture but to set clang on VS2017 up you need to install Microsoft's Platform Toolset V1.40 first:
VS2017 Clang debug
Project -> Properties -> C/C++ -> Commandline -> Options: "/Z7"

qt-creator and msvc can't add a (static) library

I have a 3rd party (closed source) static library (.lib) written in C, with a C++ compatible header and a very simple C++ test program.
After creating a new project in Qt-creator, I tried to compile the program and link to the static library, but the linker cannot resolve the symbols: "Unresolved external symbol", error LNK2019.
I am using Qt 5.3 with the compiler from VisualC++ 2013 Express (which I think is MSVC12), and the .pro file used in Qt-creator is the following:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
LIBS += -L"C:/Users/myuser/myproject" -lsomelib
SOURCES += main.cpp
HEADERS += \
somelib.h
assuming that in C:\Users\myuser\myproject there are the following two files:
libsomelib.lib
somelib.h
I am not sure about what to provide in the -l flag, so I tried with libsomelib.lib, libsomelib and somelib as I would do in Linux, but every combination was unsuccessful.
This is my first time using MSVC from Qt-creator (not that I have much experience with it), so I cannot really understand the linking command issued by qt-creator, which includes manifest files that I do not know, and - apparently - no files or libraries are listed explicitly in the command:
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\myproject.exe.embed.manifest /OUT:debug\myproject.exe #C:\Users\myuser\AppData\Local\Temp\myproject.exe.4260.531.jom
Note that if I do not use qmake and compile this example by hand using cl and link, the program links just fine. To achieve this, I use the commands:
cl /MT /EHsc /c main.cpp
link /LIBPATH:C:\Users\myuser\myproject libsomelib.lib main.obj /out:test.exe
How can I fix that? Thanks in advance!
Somehow I managed to compile the code using MSVC.
I tried to reproduce the compilation on Qt-Creator but without success; also tried to export a qmake project from VS using the Qt Add-in, but the issue persist in qt creator. So I'm giving up and continue to use VS to compile.

LINK1104 cannot open boost static library using visual studio 2008 command prompt

I'm trying to compile a cpp file which uses static boost libraries. I'm using the visual studio 2008 command prompt as I have not set up a VS project file.
The command I'm using is (run from the folder containing my source code):
cl /EHsc /I "C:\Program Files\boost\boost_1_53_0" Client.cpp
The error is:
LINK: fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-s-1_53.lib'
However, the file 'libboost_system-vc90-mt-s-1_53.lib' can be found in "C:\Program Files\boost\boost_1_53_0\stage\lib" so my understanding is that I've installed boost properly and I'm just failing to link to it?
I've tried including it directly using
cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" /I "C:\Program Files\boost\boost_1_53_0\stage\lib\" Client.cpp
which gives the same error.
I've also tried linking to it directly using /link as follows:
cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" /link "C:\Program Files\boost\boost_1_53_0\stage\lib\libboost_system-vc90-mt-s-1_53.lib" Client.cpp
Which returns a different error:
cl : Command line error D8003 : missing source filename
I seem to be calling the compiler flags wrong? But I can't see where/how.
There is a similar question here,but the solution involves issues with how visual studio/ the project file is set up. Since I don't have a project file, is there an easy solution for the above that I can't see or would I need to set up a project?
Thanks for any help in advance!
The linker needs to be told where the library file is located. You were very close with the last command line, but the file name needs to precede the /link option. This should work:
cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" Client.cpp /link "C:\Program Files\boost\boost_1_53_0\stage\lib\libboost_system-vc90-mt-s-1_53.lib"
Also, when linking to multiple libraries in the same directory, it is more concise to use the LIBPATH option to tell the linker where to look for .lib files.
cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" Client.cpp /link "libboost_system-vc90-mt-s-1_53.lib" /LIBPATH:"C:\Program Files\boost\boost_1_53_0\stage\lib\"

How to add a library include path for NetBeans and gcc on Windows?

How to add a library include path for NetBeans and gcc on Windows?
Using:
NetBeans 7.1.2
MinGW (mingw-get-inst-20120426.exe)
gcc 4.7.0
For example, you want to add the directories in C:\Program Files (x86)\Example\1.0\include\ as the include paths.
First, set up code assistance:
NetBeans > Tools > Options > C/C++ > Code Assistance
C Compiler > Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include
C:\MinGW\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include-fixed
...
C++ Compiler > Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++\mingw32
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++\backward
C:\MinGW\lib\gcc\mingw32\4.7.0\include
C:\MinGW\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include-fixed
...
OK.
The C:\MinGW\... directories are examples only. Do not actually add them. NetBeans should have detected and added the MinGW directories automatically. If not, try resetting the settings:
NetBeans > Tools > Options > C/C++
Code Assistance
C Compiler > Reset Settings
C++ Compiler > Reset Settings
Build Tools
Restore Defaults
For instructions on automatic code assistance for existing sources, see:
C/C++ Projects Quick Start Tutorial:
http://netbeans.org/kb/docs/cnd/quickstart.html#makefileprojects
How to Configure Code Assistance When Creating a Project from Existing Code:
http://netbeans.org/kb/docs/cnd/configuring-code-assistance.html
Now, configure the project options:
Right click on project > Properties
Configuration: <All Configurations>
Build
C Compiler
General
Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
Compilation Line
Additional Options:
-std=c11 -g3 -pedantic -Wall -Wextra -O0
C++ Compiler
General
Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
Compilation Line
Additional Options:
-std=c++11 -g3 -pedantic -Wall -Wextra -O0
OK.
For adding command-line options by default for all projects, see:
NetBeans settings for GCC
Any spaces in the path should be automatically escaped. Any backward slashes should be replaced with forward slashes automatically.
For example, the "All options" textbox in "Additional Options" looks like this:
-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g -I/C/Program\ Files\ \(x86\)/Example/1.0/include/shared -I/C/Program\ Files\ \(x86\)/Example/1.0/include/other -I/C/Program\ Files\ \(x86\)/Example/1.0/include
If this does not work, you may have to fix the path and add the includes manually in the additional options. For example, replace /C/ with C:/.
-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g -IC:/Program\ Files\ \(x86\)/Example/1.0/include/shared -IC:/Program\ Files\ \(x86\)/Example/1.0/include/other -IC:/Program\ Files\ \(x86\)/Example/1.0/include
If you are using Cygwin make and if you try to clean or rebuild the project with colons in the command, you may get a *** multiple target patterns. Stop. error message. According to the answers from Multiple target patterns? and Very simple application fails with "multiple target patterns" from Eclipse, "make sees the : in the path and thinks it is another target definition, hence the error."
The workaround is to delete the generated build and dist folders every time before you build your project. However, this can be annoying, so you could try MinGW MSYS make instead (not to be confused with MinGW make, which is unsupported).
For MinGW and MSYS configuration instructions, see:
Configuring the NetBeans IDE for C/C++/Fortran:
http://netbeans.org/community/releases/68/cpp-setup-instructions.html#mingw
For working with MinGW and Unicode, you should install the latest version of MinGW-w64. See:
wWinmain, Unicode, and Mingw