how to use boost libraries in mingw which are built with msvc - windows

I built boost libraries with msvc. And I want to link to my program using mingw. As the title asked, how can I achieve that?
When I try to link the boost libraries. The compiler suggests that it can't find symbols of the boost libraries.

Quoting the mingw wiki here:
Object files and static libraries created with different compilers [...] often cannot be linked together. This issue is not specific to MinGW: many other compilers are mutually incompatible. Build everything from source with the same version of the same compiler if you can.
It is stated in the same page that if you want, you may use dynamic (shared) libraries from different compilers if you provide a C interface for the library you want to use. Then your program would use this interface (C wrapper library) to communicate with Boost, by including the header for this interface library with extern "C". Example of doing this can be found here.
In your case, however, this would not be preferable as you would have to expose everything you want to use from Boost one by one in the C interface that you would write yourself. You might find it much easier just compiling your libraries with the same compiler you are compiling your program with.

Related

c++ libs from ubuntu 16.04 repo - compiler options

Ubuntu 16.04 comes with GCC 5.4 which does support c++11 and it is the default compiler. By default c++11 is not enabled in that particular version of GCC.
My intent is to use some of the binary libraries (not header only) from their repository (e.g. boost). In my projects I will enable c++ 11.
How were c++ libraries from the repository compiled? Is it possible to use them with c++ 11 enabled? I know that c++ libraries can be called from different languages (Java, Pythons, C# etc) by hiding all c++ stuff behind plain C interface. With boost it is not a case. If a certain function returns me a string or a vector or anything from STL then it is a problem. AFAIK STL objects binary representation depends on compiler flags (eg. std=c++11).
Thank you.
Which exact libraries are you talking about?
If you are talking about the standard library, libstdc++ is a part of gcc. It is always okay to link it no matter which standard you compile at. gcc also made a decision to include ABI tags, so that they can be ABI compatible with code compiled at C++11 and pre C++11. See for instance TC's really nice answer to a question I asked here:
Is this simple C++ program using <locale> correct?
If by
How were c++ libraries from the repository compiled?
you mean, how are all of the C++ libraries in the ubuntu repositories compiled, the answer is, it may be different for each one.
For instance if you want to use libfreetype6-dev or libsdl2-dev, these are C libraries, they will be okay to link to no matter what standard you target.
If you want to use libsilly-dev from CEGUI, that is a C++ library, and it is usually best to use the exact same compiler for your project and the C++ lib that you are linking to. If it appears in ubuntu repository, you can assume it was built with the default g++ version that ubuntu is shipping. If you need to use a different compiler, it's probably best to build the C++ lib yourself -- in general C++ is not ABI stable across different compilers, or even different versions of the same compiler.
If you want to use compiled boost libraries, it's probably best to use the libs they give you and use the compiler they give you. If you only use header-only boost, then the compiler doesn't matter since you don't actually have to link with something they built. So you then have more flexibility with respect to compilers.
Often, if you need to use C++ libraries, it's best to integrate their build system into yours so that it can be easily rebuilt from source and you only have to configure the compiler once. (At least in my experience.) This can save a lot of time when you decide to upgrade compilers later. If you use cmake then it's often feasible, but sometimes this can be hard, especially if you have a lot of C++ dependencies. If you don't use cmake, well, many libraries use cmake and it won't be that easy to integrate them this way. cmake is still kind of a pain anyways, so this might not be such a loss.

How to remove libgcc_s.so dependencies from uclibc

My understanding is that libgcc shouldn't be used in embedded systems and uclibc need to be used wherever possible. During buildroot build it is seen that it is generating libgcc as well. If I have to remove libgcc dependency completely (no static as well as shared) and only rely on uclibc, is it possible ? Is there any configuration which can effect this change ?
Thanks.
You are confusing glibc with libgcc. The latter contains helper functions for your architecture (e.g. integer division on ARM Application Profile) and not the standard C library functions. These functions may be part of the "run-time ABI" and might be required regardless of the C library you are using (even when compiling for bare-metal).
The uClibc is a drop-in replacement for glibc, not for libgcc.

Is it possible to compile/link to occi with gcc on HPUX?

We have Oracle 11 running on HP-UX 11.31 and gcc 4.4.3. It seems that there is no way to link to occi, because it was built with aCC. Is there any workaround for this?
I had the silly idea that I could somehow build a library that basically proxied the connection - build the library with aCC in some way that could be linked to by gcc. Is this possible?
No, there isn't a way around that.
Different C compilers have interchangeable code using a standard ABI. You can mix and match their object code more or less with impunity.
However, different C++ compilers have a variety of different conventions that mean that their object code is not compatible. These relate to class layout (especially in multiple inheritance hierarchies and the dreaded 'diamond-of-death'), but also in name mangling conventions and exception handling. The name mangling schemes are deliberately made different so that you cannot accidentally link objects from one compiler with another.
Generally, if libraries are built using a C++ compiler, you have to link your code using the same - or at least a compatible - C++ compiler. And that almost invariably means a compiler from the same family. For example, you might be able to use G++ 4.5.0 even if the code was built with G++ 4.4.2. However, you won't be able to mix aCC with G++.

calling C/C++ functions of a library compiled with g++, wthin a program compiled with gcc

I have a set of software library modules which are developed in c++. So, I use g++ to compile my software.
This has to be used by various existing applications which are written in C and compiled with gcc.
When the other teams used g++ to compile their code, they started getting lot of compiler errors due to strict type checking rules of c++. This broke their applications. Worse still, they are using some 3rd party library code, which cannot be compiled using g++.
if they use gcc, then there are linker errors (unresolved symbols).
so, my question is...
"Is there a way for my library code to be linked with their applications, without changing the respective compilers? That is, i still have to use g++, since i use classes/objects heavily in my code, and they have no choice of using g++, which will break their application?".
Thank you for kind help.
regards,
Ravindra
One of the problems you may be experiencing could be the result of different versions of g++ having different ABI formats. at very least, don't expect versions of G++ prior to 4.1 to work with code compiled with 4.1 or later.
Intermingling C and C++ requires that the C++ code all export a C compatible interface. This is done by declaring free functions (cannot be used on classes) with the extern "C" specifier. (some notes on the c++ faq lite_
extern "C" {
#include "c_language_headers.h"
int c_accessible_function(int);
struct c_accessible_datatype { };
}

zlib + masm

Can zlib be used with masm without all the c runtime libraries such as msvcrt.dll and many others?
If so, can you tell me how?
zlib does include optimised assembler for various processors and assemblers including masm. But that assembler is only for the innermost parts of zlib. It's not, in other words, a complete reimplementation of zlib in assembler. Using the masm chunks therefore won't change the dependencies that zlib has.
That said: it should be possible to statically link your application, including any of the C runtime library features that you're using and not having external dependencies.
Then again, msvcrt.dll is present on pretty much every Windows system anywhere, so why would you want to do this?
Zlib is not a C++ library so I don't understand why you would need C++ runtime libraries to use it.
I think you mean C libraries.
it depends on what you want to do, if you just want to decompress data, i would recommend TINF library from Joergen Ibsen, those assembly implementations from ZLIB package are pretty useless and will give you a headache ;)

Resources