I had Microsoft Visual Studio Community 2013 (Version 12.0.31101.00 Update 4) and Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017) on my PC with Windows 10 Pro.
In order to try examples with Boost.Python I downloaded boost 1.64.0 and build libraries by b2 with options --with-python --toolset=msvc --build-type=complete. As a result I have the following files:
boost_python3-vc120-mt-1_64.dll
boost_python3-vc120-mt-1_64.lib
boost_python3-vc120-mt-gd-1_64.dll
boost_python3-vc120-mt-gd-1_64.lib
libboost_python3-vc120-mt-1_64.lib
libboost_python3-vc120-mt-gd-1_64.lib
libboost_python3-vc120-mt-s-1_64.lib
libboost_python3-vc120-mt-sgd-1_64.lib
libboost_python3-vc120-s-1_64.lib
libboost_python3-vc120-sgd-1_64.lib
Then I created project (type: Win32 / DLL) in Visual Studio with the following code taken here:
char const* greet()
{
return "hello, world";
}
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello)
{
using namespace boost::python;
def("greet", greet);
}
In project properties for C/C++ settings I added "Additional Include Directories" to locations of Boost and Python (ends with \Python36\include).
During the first attempt to build the project an error appears:
Error 1 error LNK1104: cannot open file 'python36.lib'
So in project properties for Linker settings "Additional Library Directories" I added corresponding location (ends with \Python\Python36\libs). After that I could move on ... to the next error:
Error 1 error LNK1104: cannot open file 'boost_python-vc120-mt-gd-1_64.lib'
It is noteworthy that the difference in filenames I had and VS2013 looking for is just digit 3 after word python.
Similar questions at stackoverflow and in google groups are discussed but without valuable tips. The only useful information is that library file names *boost_python-* corresponds to Python 2 and *boost_python3-* to Python 3.
I noticed that changing the build type (Solution Configuration) from Debug to Release leads to change the error message in part of library file name (there is no -gd- now):
Error 1 error LNK1104: cannot open file 'boost_python-vc120-mt-1_64.lib'
I suppose, VS2013 knows boost library file name convention, but probably does not know the difference about Python 2 and Python 3.
So, I have 3 questions:
Is it possible to influence the logic used by VS to look for Boost.Python library? (Of course lib-files renaming is also an option, but I do not like this for some reason)
Do the linker options allow specifying lib-file directly? (i.e. I can write whole path to the boost_python3-vc120-mt-1_64.lib including file name, not just folder name in section "Additional Library Directories")
What option in the project properties should make VS2013 to use different LIB or DLL files, e.g. libboost_python3-vc120-mt-1_64.lib or boost_python3-vc120-mt-1_64.dll instead of boost_python-vc120-mt-1_64.lib?
With the community help I have found answers to couple of the questions.
Is it possible to influence the logic used by VS to look for Boost.Python library?
Name of library depends on value defined as macro BOOST_LIB_NAME in file boost/python/detail/config.hpp.
I have tried to change line (108 in boost 1.64.0)
#define BOOST_LIB_NAME boost_python
to
#define BOOST_LIB_NAME boost_python3
And desirable library file changed from boost_python-vc120-mt-1_64.lib to boost_python3-vc120-mt-1_64.lib.
It should be noted, that instead of changing values in config.hpp file auto_link.hpp can be created and used with redefinition of BOOST_LIB_NAME.
What option in the project properties should make VS2013 to use different LIB or DLL files, e.g. libboost_python3-vc120-mt-1_64.lib or boost_python3-vc120-mt-1_64.dll instead of boost_python-vc120-mt-1_64.lib?
That is also regulated by defines.
In particular, adding to the beginning of my code (before #include <boost/python.hpp>) the line
#define BOOST_PYTHON_STATIC_LIB
forces MSVS to search file libboost_python3-vc120-mt-1_64.lib (or libboost_python-vc120-mt-1_64.lib), i.e. static lib.
And vice versa line
#define BOOST_PYTHON_DYNAMIC_LIB
or
#define BOOST_ALL_DYN_LINK
can be used to import code from a dll.
Related
I'm trying to generate code metrics for a C++ project which is not a Visual Studio one, rather it was written on Linux.
I tried the Project Maker and followed the steps except for the last part (After adding the source files, you can specify the project properties). I did not know what to input. So, I proceeded and when starting the Analysis it gives so many clang parsing errors such as
"string" file not found at "path/xyx.hpp"
fstream file not found at "path/ii.hpp"
though I can see in xyx.hpp that there is a line #include <string>
From the projectmaker configuration you have to specify the include path where the stl library exists. For that right click the project in projectmaker choose properties and added the include path directories separated by ;
I am currently using Visual C++ 10.0(2010) on a win7 32bit OS.
When I tried to build the basic examples of libigl github tutorials:
libigl tutorials
The following installation code works fine:
#include <igl/cotmatrix.h>
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <iostream>
int main()
{
Eigen::MatrixXd V(4,2);
V<<0,0,
1,0,
1,1,
0,1;
Eigen::MatrixXi F(2,3);
F<<0,1,2,
0,2,3;
Eigen::SparseMatrix<double> L;
igl::cotmatrix(V,F,L);
std::cout<<"Hello, mesh: "<<std::endl<<L*V<<std::endl;
return 0;
}
which indicates there is basically no problem per the tutorials.
However, I cannot get the tutorial 102 through:
#include <igl/readOFF.h>
#include <igl/viewer/Viewer.h>
Eigen::MatrixXd V;
Eigen::MatrixXi F;
int main(int argc, char *argv[])
{
// Load a mesh in OFF format
igl::readOFF("../shared/bunny.off", V, F);
// Plot the mesh
igl::viewer::Viewer viewer;
viewer.data.set_mesh(V, F);
viewer.launch();
}
After getting a series of building error message of missing some special headers, and then adding the corresponding directory containing the header into the including directory of VS, there is still some header missing which cannot be found in my computer.
Except for the include directory which is required per the tutorial:
x:\Program\libigl-master\include; $(IncludePath);
I already added others as follows:
x:\Program\libigl-master\external\glfw\include;
x:\Program\libigl-master\external\AntTweakBar\src;
x:\Program\libigl-master\external\AntTweakBar\include;
x:\Program\libigl-master\external\glew\include;
Error message is still there:
x:\Program\libigl-master\external\glfw\include\glfw\glfw3.h(163): fatal error C1083: Cannot open include file: 'GL/glcorearb.h': No such file or directory
1>
So I added:
x:\Program\libigl-master\external\glfw\include\GLFW
D:\Program\libigl-master\external\glfw\include\
and got:
x:\program\libigl-master\external\glfw\include\glfw\glfw3.h(163): fatal error C1083: Cannot open include file: 'GL/glcorearb.h': No such file or directo
which does not exist in my computer.
What should I do?
I had the exact same issue, and the thing is that simply adding their include paths won't make it work - as they said it would. That is because LIBIGL itself is just an auxiliary library to help manipulate 3D shapes, but their examples use much more than that (their matrix system comes from Eigen, their graphical system uses GLFW+GLEW, among many others).
But you can get most of the examples working on MSVS setting up the essential libraries. Download the following:
Eigen: This is for the basic matrix/vector arithmetics etc.
GLFW: This is used to create and handle windows for OpenGL.
GLEW: This library has the actual OpenGL function bindings to use OpenGL functions.
Note that these libraries are essential to compile the examples jut because when the examples were made, the creators had the enviroment set up with them (otherwise they would have to code by hand those OpenGL and Windows/Linux windows handling etc. In case you're interested, this is what "pure OpenGL" code looks like). So what you have to do is: set the enviroment for these libraries. This is how to do it:
After creating an empty project in MSVS, go to Solution explorer > right click the project > Properties. You've opened the Property Pages, where all the project configurations are done. We need to specify 3 things: where the compiler can find the headers, the libraries we're using and where it can find these libraries.
First we set up the headers: on the left menu expand C/C++ > General, and on the right, select Aditional Include Directories, click on the down arrow and click edit. A window will open with blank fields, click them twice to add items. Add the eigen header path, the libigl folder path, the glew folder path and the glfw folder path in each line (this is a very confusing interface).
Ok, now we need to specify which libraries we're going to use. Again, in the left menu, go to Linker > Input > Aditional Dependencies (almost the same kind of interface). Add glew32s.lib, glfw3.lib and opengl32.lib (one for each line). Finally, specify where those libraries are. Go to Linker > General > Aditional Library Directories, and specify the path where the downloaded glew32s.lib and glfw3.lib are. (something like "C:\Users...\glfw-3.2.1.bin.WIN32\lib-vc2010") - make sure you're specifying the path to the right compiler - for instance, if you're using MSVS 32 bits 2010 you should select vc2010 and not mingw-64.
If you create a source file in the project using the tutorial 2012 source code it should compile, but you might have to specify the paths to the dll's such as OpenGL32.dll if it's not already in your system path.
Finally, one last thing that might go wrong has to do with something called Runtime Library - it's in C/C++ > Code Generation > Runtime Library. Basically it describes a method to compile code, and each library we're using was compiled using a different one, so we might get errors... Honestly I don't know a lot about that, I just know that mine wasn't working with the default one, so I changed to /MD and it worked. Go figure.
PS: You might as well need to update your graphics card for OpenGL to work.
The only thing that worked for me was creating a visual studio project with cmake-gui. Here is what I did:
Download and install cmake https://cmake.org/download/.
Open cmake-gui.
In 'where is the source code', put the path to the tutorials: .../libigl/tutorial.
In 'where to build the binaries', put whatever your like (I used .../libigl/tutorial/build).
You will also see a bunch of options in red. Select/deselect as desired. I had to deselect Matlab as it couldn't find it for some reason.
Configure and generate (when asked, choose whichever version of Visual Studio you are using).
You should now have a Visual Studio solution in the build folder. Open and build.
I had the same problem in Visual Studio 2013. And the head file I was trying to use was igl/sort.h which cannot be opened.
In the tutorial , they said
Simply add libigl/include to your include path and include relevant headers.
And the include path they were referring here is actually the include directories which can be found under project>properties>Configuration Properties>VC++ Directories, not the Additional Include Directories.
I'm working in a Cocos2dx (c++) win 32 project and trying to use sqlite to save the game data. My knowledge of c++ / Visual Studio is very limited right now.
This is part of the code that I'm trying to compile.
#include <sqlite3\include\sqlite3.h>
...
void HelloWorld::SaveAndLoadTest()
{
sqlite3 *pdb = NULL;
sqlite3_open("writablePath", &pdb);
...
}
But when I try to compile the line with the sqlite3_open command I get the following error:
Error 7 error LNK2019: unresolved external symbol _sqlite3_open referenced in function...
I've been trying to find an answer for this many hours. The most similar question I found was this one but I don't understand the answer.
Error: undefined reference to `sqlite3_open'
You need to link the sqlite3 library along with your program:
g++ main.cpp -lsqlite3
I'm new to Visual Studio and I don't understand how to solve this, anyone?
The error LNK2019 means that references are missing probably because a library is mising.
To add sqlite to a MSVC project, you have to make sure that:
the header is included in your source files
sqlite3.dll is in the path or in the directory of the executable
AND that sqlite3.lib is added to the additional dependencies in the VS project (options of the project > Linker > Input > Additional dependencies)
This last point is mandatory, because the lib tells the linker which functions are stored in the dll.
The solution, quite simply, is to link sqlite3 to your project. Libraries need to be linked (via the linker) for you to be able to use them. Head over here and download the pre-compiled binaries for your platform of choice (in this case, Win32). You may also choose to compile sqlite3 from source. You should end up with a .lib file. Go to Project -> Configuration Properties -> Linker -> General -> Additional Include Directories and add the path to your library file to it. Then go to Linker -> Input -> Additional Dependencies and put in sqlite3.lib.
And remember that you must build sqlite3.lib from file SQLite3.def:
Download source from source (https://www.sqlite.org/download.html)
For example: source https://www.sqlite.org/2022/sqlite-amalgamation-3390300.zip
Or download binary from binary
For example: binary https://www.sqlite.org/2022/sqlite-dll-win64-x64-3390300.zip
Extract both archives to the same directory
Open Developer Command Prompt for VS 2017 by typing Developer Command in Windows Search
Go to directory where you've extracted source code and binary files (via opened cmd)
Run lib /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64
(Remember if win32, replace "MACHINE:x64" by MACHINE:x86)
I am trying to link FMOD to my project, which I did very easily in the past in Visual Studio 2008.... So I have placed the fmodex_vc.lib and the fmodex.dll file in my project directory, added them to my project's solution explorer, then created a SoundMgr.h file which includes the fmod.h file
#include "include\fmod\fmod.h"
Where fmod has been placed in the include\fmod folder and opens ok if i right click on the above code and click "Open Document"...
But if I try to write any code at all, including a simple "using namespace FMOD" it tells me that it FMOD is undeclared or unidentified.... am I missing any step?
EDIT:
What the class looks like so far is:
#pragma once
#include "main.h"
#include "include\fmod\fmod.hpp"
#include "include\fmod\fmod_errors.h"
#include "include\fmod\fmod.h"
class SoundMgr{
void init();
};
void SoundMgr::init(){
FSOUND_Init (44100, 32, 0);
}
And the error is:
Error 1 error C3861: 'FSOUND_Init': identifier not found
And that's for any line of the sample code that I try import from this quick guide:
GameDev FMOD quick guide
I tried adding the library as an additional dependency in the Input section of the Properties/Linker and I get
1. fatal error LNK1181: cannot open input file 'fmodex_vc.lib'
Any of these errors ring a bell?
Don't you want fmod.hpp to get the c++ features?
you can include the headers path in C/C++ > General and library path to Linker properties and include the dll's in you project. In this case you have the files in you release/debug dir
Right so I eventually fixed it by removing the Additional Dependency in the Input section of the Linker and instead adding Include and Library directories in in Configuration Properties\VC++ directories.... Most articles I found advise to use the actual full path to the FMOD installation folder, but since I want this project to be portable and self contained, i created a "lib" and "include" folder in my project and put those files in them... (used the directories "\lib" and "\include" in the project properties which I am assuming links to the project folder, have never done this before but am hoping it won't cause dependency issues if I compile this on a different machine)...
I am having trouble getting my project to link to the Boost (version 1.37.0) Filesystem lib file in Microsoft Visual C++ 2008 Express Edition. The Filesystem library is not a header-only library. I have been following the Getting Started on Windows guide posted on the official boost web page. Here are the steps I have taken:
I used bjam to build the complete set of lib files using:
bjam --build-dir="C:\Program Files\boost\build-boost" --toolset=msvc --build-type=complete
I copied the /libs directory (located in C:\Program Files\boost\build-boost\boost\bin.v2) to C:\Program Files\boost\boost_1_37_0\libs.
In Visual C++, under Project > Properties > Additional Library Directories I added these paths:
C:\Program Files\boost\boost_1_37_0\libs
C:\Program Files\boost\boost_1_37_0\libs\filesystem\build\msvc-9.0express\debug\link-static\threading-multi
I added the second one out of desperation. It is the exact directory where libboost_system-vc90-mt-gd-1_37.lib resides.
In Configuration Properties > C/C++ > General > Additional Include Directories I added the following path:
C:\Program Files\boost\boost_1_37_0
Then, to put the icing on the cake, under Tools > Options VC++ Directories > Library files, I added the same directories mentioned in step 3.
Despite all this, when I build my project I get the following error:
fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-gd-1_37.lib'
Additionally, here is the code that I am attempting to compile as well as a screen shot of the aformentioned directory where the (assumedly correct) lib file resides:
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
#include <iostream> // for std::cout
using boost::filesystem; // for ease of tutorial presentation;
// a namespace alias is preferred practice in real code
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
return 0;
}
Ferruccio's answer contains most of the insight. However, Pukku made me realize my mistake. I am posting my own answer to give a full explanation. As Ferruccio explained, Filesystem relies on two libraries. For me, these are:
libboost_system-vc90-mt-gd-1_37.lib
libboost_filesystem-vc90-mt-gd-1_37.lib
I must not have noticed that when I supplied the directory for libboost_filesystem-vc90-mt-gd-1_37.lib, the error output changed from
fatal error LNK1104: cannot open file 'libboost_filesystem-vc90-mt-gd-1_37.lib'
to
fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-gd-1_37.lib'
Causing me to think that the error was persisting. This lead me to post some rather inaccurate information. Also, after reading that Filesystem requires two libraries, I now see the significance of the keyword stage for the bjam command. Supplying
bjam --build-dir="C:\Program Files\boost\build-boost" --toolset=msvc --build-type=complete stage
Causes bjam to place an additional directory, aptly named stage, in the boost_1_37_0 directory. This folder contains a folder named /lib, which has copies of all of the lib files in one place. This is convenient for Visual C++ because you can supply it with this single directory and it will take care of all of the dependencies.
boost::filesystem is dependent on boost::system, so you need both paths.
Part of the problem is you're using the boost libs out of the build directories instead of the install directory (the boost build process should create both). The install/lib directory has all the libs so you only need to specify one path.
The boost build process builds each library in its own directory. At the end it copies all those .lib files into one common lib directory.
Since you didn't specify an install directory as part of your build command (with --prefix=...), I believe the default is C:\Boost. Check to see if that directory is there and if so use C:\boost\include\ boost-1_37 for your include path and C:\boost\lib for your library path.
Last answer is right.
But you should find boost config file $BOOST\config\user.hpp and
uncomment this directive #define BOOST_ALL_DYN_LINK.
Now it begin use dynamic link with boost and it should works.
I think the real original problem is related to the default boost build process on windows which expects static linking of a library which will have a name beginning libboost_sytem<etc..>. The macro you need is
#define BOOST_SYSTEM_DYN_LINK
which makes ensures that the Boost.System library is dynamically linked. The dynamic library name is boost_system<etc...> as apposed the the static library libboost_sytem<etc...>
The bjam command line should have built all versions of all libraries. Still, when you build with
bjam --build-dir="C:\Program Files\boost\build-boost" --toolset=msvc --build-type=complete stage
(note the stage at the end) all libraries are copied to a common libs/ folder, so that MSVC's autolinking feature works when you only add this libs/ folder to your library path.
I do not know if bjam without stage still copies all those files to a single folder. If not, execute such a stage build to do this. If they are, well, sorry, configuration seems correct, maybe a minor typing error somewhere?
The error you have posted complains about file libboost_system-vc90-mt-gd-1_37.lib, but in the directory you have only libboost_filesystem-vc90-mt-gd-1_37.lib, right?
Look for libboost_system-vc90-mt-gd-1_37.lib. If you find it, add the corresponding directory to the library search path. If you don't find it, see if you have boost_system-vc90-mt-gd-1_37.lib instead (like I do), and try copying that to the desired filename.
I had this same problem, what you need to do is add the "lib" directory under the top level boost folder to the library path in Visual C++.
This most definitely solved the issue for me.