How to do static linking in Eclipse CDT? - c++

I am trying to statically link to a third party C library in C++.
I managed to do this in Visual Studio just by specifying the .lib file in the linker input options. However, when I do the equivalent in CDT (Project Properties -> Settings -> MinGW C++ Linker -> Libraries) I get endless amounts of "undefined reference to..." errors when I try to build.
Is there anything else that I need to do to achieve static linking in CDT?
Thanks,
Alan

If that third party library is build for Visual C environment and with the Microsoft Visual Studio compiler, you might be unable to link it with the MinGW compilers.
However, you can configure Eclipse CDT on Windows to compile your code with the Visual Studio command line compiler CL.EXE and then things should work as you expected.
It heavily depends on which version of Eclipse CDT you are using, because the Microsoft compiler settings plug-in is only part of the newer versions (I think its from Helios on).

Related

Can MySQL's Connector/C++ work with Visual Studio 2017?

I kept hearing Connector/C++ should run on the compiler that it was compiled on, and one document says that's Visual C++ 2013. I'm using Visual C++ 2017 and I'm not downgrading. The document may have been old, so I'm curious if anyone has had any success and what you did to make it work.
Yes it will definately work. You just have to add include path and library path of MySQL to your VC++ directories ( Project -> Properties -> VC++ directories).
Now that you have included path you can directly use mysql.h header to call mysql c functions.
No, for C++ you have to find a version that got compiled with the same settings as your project. You can switch to using the C version of the connector which does not suffer from C++'s lack of ABI. You can find the C tutorial here.
If you would like to try your luck with C++, then make sure the build settings of the library you use match your project:
version of Visual Studio
version of stl
exception handling
vtable layout
stack and stack frame padding
Bitness (32 vs 64)
Iterator debug level
runtime linkage (MT vs MD)
build configuration (Debug vs Release)
characterset (multibyte vs unicode)
Fortunately the linker will check the compiler version _MSC_VER and will not allow you to link to the older library.

MSVCP140.dll missing

I just developed my first program in C++ and I wanted to share it with one of my friends.
But when he tries to open the exe it gets an error which says "MSVCP140.dll is missing". Why is this issue happening and how can we fix it?
Either make your friends download the runtime DLL (#Kay's answer), or compile the app with static linking.
In visual studio, go to Project tab -> properties - > configuration properties -> C/C++ -> Code Generation on runtime library choose /MTd for debug mode and /MT for release mode.
This will cause the compiler to embed the runtime into the app. The executable will be significantly bigger, but it will run without any need of runtime dlls.
Your friend's PC is missing the runtime support DLLs for your program:
Visual C++ Redistributable for Visual Studio 2015
That usually means that your friend does not have the Microsoft redistributable for Visual C++. I am of course assuming you are using VC++ and not MingW or another compiler. Since your friend does not have VS installed as well there is no guarantee he has the redist installed.
VC++ Distro
That's probably the C++ runtime library. Since it's a DLL it is not included in your program executable. Your friend can download those libraries from Microsoft.

Upgraded C++ Project to VS2015, but the Linker is still looking for VC100 Boost library

I have upgraded my C++ project from VS2008 to VS2015.
The Platform Toolset is set to Visual Studio 2015 (v140). If it matters, the Target Platform Version is set to 8.1.
I built boost using toolset=msvc-14.0 and put the built libraries into the place my project is expecting them.
When I build my project, I get a linker error:
LNK1104 cannot open file 'libboost_thread-vc100-mt-1_43.lib'
Why is it looking for the vc100 library and not the vc140 one?
It's the first project out of 2 that is failing.
In the .vcproj file there is no reference that I can see to vc100.
Linking to boost libraries on Windows is done automatically through auto linking and #pragma directives. The version number it looks to link against is defined in boost\config\auto_link.hpp where it goes through a bunch of #if and #elifs on your MSVC version and if the version is higher than any of the ones it knows about then it just sets the version number to the highest one it knows about. For boost 1.57 that is vc140, for your version of boost that is presumably vc100.

MSVCR100D.dll is missing when build/running project from another PC/VS

I uploaded my (VS2013) project folder and provided it to the other members of my team, but when they tried to build/run it, using Visual Studio 2012 they got this error, it also happened on their version of Visual Studio 2013.
The program can't start because MSVCR100D.dll is missing from your computer. Try reinstalling the
program to fix this problem.
They reinstalled VS2010 but no go.
I also tried to statically link my project by using /MT in the Code Generation options but now I get:
Unresolved External Symbol __free_dbg libcmptd.lib cout.obj
....25 more...
How can I get it so my project can be build/ran on my team members pc? How do I resolve the unresolved externals? It seems to happen purely with regular Microsoft files.
You are mixing C++ libraries built with different versions of the compiler (and as we know some of them are linked against debug dynamic version of VC10 runtime library). This is not supported, as different compiler versions have different ABIs.
To fix the mess you need to find libraries built with parameters that match parameters of your project. They should be built:
with the same compiler version (ex. VS 2013)
with the same configuration (Debug/Release)
against the same platform (x86/x64/ARM)
against the same runtime library variant (static/dynamic + debug/release)
You could either try to find prebuilt versions on the web or to build libraries yourself from source codes. Often, you will want to have multiple configuration/platforms for your project and, thus, you will need multiple versions of your libraries.
If your search will not succeed (for example if there is no VS2013 build for a closed source library) you could roll back your project to another version of compiler and to start over.
Any attempts to link incompatible libraries even if somehow succeeded will lead to random crashes.
This message generally states that the dll is referred to directly or indirectly in your application and is missing.
The 'D' at the end show us this is the Debug version of the file, this is DLL file is provided with the Visual Studio 2010 installation. So the MSVCR100D.dll would be provided with the installation of Visual Studio 2010.
Of course, you could be missing other versions 2008 (MSVCR90D) 2010 (MSVCR100D) 2012 (MSVCR110D) or the 2013 (MSVCR120D), each dll is provided according to the Visual Studio version.
There are a few ways to solve this:
Check to be sure that you're compiling all the components of your
project in Release mode. If this does not solve the issue continue
to the next steps.
You could solve this locally by installing Visual Studio 2010 on your
machine. This is not what I would recommend, but it would surely
overcome the issue
You could also download the file from this third party website and
copy it to your projects bin:
http://www.dll-files.com/dllindex/dll-files.shtml?msvcr100d
This option is the LEAST recommended option.
Run dependency Walker and see what file depends on the MSVCR100D.dll
and the try and fix that file in order to break your dependency. You can download depends here: http://www.dependencywalker.com/
Check to be sure that you're project is linking the correct version of
the CRT and any other libraries you may be using (e.g., MFC, ATL,
etc.)
Note: Installing the redistributables alone will NOT solve this problem, since the redistributables only contain the release version of the file MSVCR100.dll (notice no 'D')
Would it be possible that in your project you are somehow using some component/library built with Visual Studio 2010, which requires the MSVCR100D DLL?

C++ coding in eclipse...help with code assist

How can i get C++ coding in eclipse to act like coding in java?
In java, i can nicely add external jar files and the code assist can nicely suggest methods or suggest adding unimplemented methods for interfaces.
But in C++ mode, it doesn't seem to work when i include external header files. What else should i try?
Eclipse CDT itself does not come with any compilers/libraries therefore you need to select and install a toolchain. There are a few options for this
Visual Studio (cl)
MinGW (g++)
Cygwin (g++)
Note, you can get VS Express for free and if you are a student can even get the professional version from Dreamspark
Once you have installed any of these you can select them as the toolchain for your C/C++ projects, this will enable you to build your projects nicely from within eclipse.
Also, you may need to point eclipse to the library files used by your compiler, for instance I use the VS2010 toolchain under Eclipse CDT so I must add
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include"
to the include directories in build settings.
Edit: Sorry if it wasn't clear, once you've done this code completion should work for your C/C++ projects.