gcc compiled library on VS using ext/hash_map - c++

I'd like to use a library I've compiled using Cygwin GCC (.a) in a Visual Studio C++ project. When I include headers from the library in VS, the ext/hash_map header is missing. Is that a header file I can just add and replace with hash_map, or is it all together hopeless (because the library doesn't make heavy use of hash maps)? Moreover, is it ridiculous to hope VS can use the .a library? Thanks!

You cannot mix GCC generated .a files with Visual Studio.

Related

How can I create .o and .a files in ELF format for Windows for the use with C++Builder 10.3.3?

I'm working with Embarcadero C++Builder 10.3.3, and would like to use OpenCV with it. However, the precompiled OpenCV pack is precompiled with Visual Studio, which uses the COFF format. However, the C++Builder 64-bit compiler uses the ELF format under Windows, per Upgrading Existing C++ Projects to 64-bit Windows:
Object and Library File Format
BCC32 and its associated tools use OMF in .obj and .lib files.
BCC64 uses ELF in .o and .a files.
Of course, I tried to compile the OpenCV source code with C++Builder, but I failed miserably. A Google search didn't find anything really helpful either, except that others also didn't succeed.
Does anyone know a CMake-compatible compiler that can generate object files (.o) and static libraries (.a) for Windows to compile OpenCV (for Windows, not for Linux, because BCC64.EXE is a Windows compiler)?
I'm also trying to use OpenCV with C++Builder (I couldn't write a comment because this is my first contribution!).
I could create the lib file with mkexp from the precompiled dll (opencv_world452.dll in \opencv\build\x64\vc15\bin) as Remy suggested.
But I have problems with the header files: How to set include path that the statement #include "opencv2/core.hpp" is accepted by the compiler? "core.hpp" also has such include statements. So, do we need to change all these #includes (\ instead of /)?
As a workaround you could try to use the Delphi-OpenCV library (https://github.com/Laex/Delphi-OpenCV) or install Python4Delphi in C++Builder and use OpenCV via Python.

Use MinGW static library (.a) within Visual studio environment

I work on a project that generate several static libraries (.a) from MinGW with Scons project files.
And I need to use these libs into an other project that work on C++ Visual Studio 2013.
First I tried to just add MinGW lib to my VS project and obviously it didn't work out.
I read some things about using a ".def" file to switch from ".lib" to ".a" but found nothing about convertion from ".a" to ".lib". But I have no idea how to get this ".def" file.
Does anyone have some clue that what I am trying to realise is possible (use MinGW into VS2013) ? Or even a solution that can help me :)
Mathieu.

libboost_system on Windows

While compiling a DLL in Visual Studio 2013 I include some boost (1.58) header files. One is <boost/system/error_code.hpp>. As it is known this will require to link to a boost lib, by default. However, I want to use the header only variant and not handle yet another library. For that I figured out how to make it work on Linux + Mac. However, I cannot get this to work on Windows. The linker always wants that additional library (libboost_system-vc120-mt-gd-1_58.lib)
What's the trick in Visual Studio to avoid linking to that lib?
Ok, I found it myself. This is not mentioned anywhere in questions about boost libs including on Windows. But if you search for disabling boost auto linking (which is actually the culprit including the libs) you will find the solution: define BOOST_ALL_NO_LIB at project level (in addition to the header only flag mentioned in the other question).

c++ windows, compile with mingw as static library and include in visual studio c++ project

c++, windows (in my case windows phone 8, arm & x86 for emulator). I've compiled boost libraries with mingw. as a result I have such files for ex "libboost_random-mgw48-mt-sd-1_53.a".
Is there any possibility to include this static library in visual studio c++ project? Maybe compile with special options... or convert this ".a" file to a visual studio compatible ".lib" file.
I've tried to rename .. but I receive some 'undefined reference' errors.. so they're not directly compatible.
please note that this library (boost) cannot be compiled with visual studio. I've an open question that still has no answer: https://stackoverflow.com/questions/23831050/compile-boost-as-static-library-for-windows-phone-8-arm
You can't use the g++ object files with visual c++. However, you can use all the header only modules of boost without building anything. For the rest, such as Boost filesystem, build it with visual c++ for use with visual c++.
Re
“please note that this library (boost) cannot be compiled with visual studio”
that's incorrect.

DLL include unordered_map is not compiling with visual studio compiler

I am trying to compile a DLL with MinGW and use it from an executable compiled with visual studio compiler.
One of source files from DLL is using hash_map<> and it can be compile with MinGW successfully.
When I change hash_map<> to std::tr1::unordered_map<> and add #include <tr1/unordered_map> to my code it's compiling successfully for visual studio compiler.(How can I force MinGW to use tr1 namespace?)
But When I am trying to compile the code with MinGW as a DLL and use it from an executable compiled with visual studio compiler it's giving error: cannot open include file 'tr/unordered_map'
must My DLL be compatible with cl and MinGW same time?
EDIT:
my commands for compiling are below:
g++ -shared -o stemming.dll stemming.cpp alphabet.cpp basic.cpp determinise.cpp fst.cpp hopcroft.cpp operators.cpp utf8.cpp -Wl,--output-def,stemming.def,--out-implib,libstemming.a
lib /machine:i386 /def:stemming.def
cl sfstMinGW.cpp SFST/stemming.lib
VC++ is trying to open a header file and can't find it in the include path. VC uses the INCLUDE environment variable to determine the paths to use when searching for header files. Since VC does not use the tr/ directory it's not going to find it. You need provide include statements for both VC and g++ and choose which one to use like below.
#if defined(_MSC_VER)
# include <unordered_map>
#else
# include <tr/unordered_map>
#endif
You need to make sure that you compile the application using the same implementation of unordered_map used by the DLL. This means you will need to update the include paths to use GCC's version of TR1 instead of MS's implementation of the standard headers.