How to link against .a files in Visual Studio 2012? - c

I have some static libraries in the form of .a files, and accompanying header (.h) files. How can I tell the linker Visual Studio 2012 Windows Desktop Express to reference these files so that I don't get "unresolved external symbol" errors when I try to build?

Include the .h header files, and make sure they are present in your project
Go to Project Properties > Configuration Properties > C/C++ > General > Additional Include Directories and add the path to the include directory where your header files can be found
Go to Project Properties > Configuration Properties > Linker > General > Additional Library Directories and add the path to the lib directory where your .a files can be found
Go to Project Properties > Configuration Properties > Linker > Input > Additional Dependencies and add the .a file accurately
Apart from this make sure you are in the correct configuration platform while building (x86 vs x64) and it is same as the one your library uses.

As far as I'm aware, you can't. They're usually using a different internal binary format the linker won't be able to understand. In a similar way, MinGW won't be able to use Visual Studio's lib files (except when using an additional tool to convert them).
You'll have to recompile the library from source or obtain library files that are compatible with Visual Studio.

Related

How to add libusb in Microsoft Visual studio 2013

I am using Microsoft Visual Studio 2013, how can I add the external library libusb to my project?
libusb will contain a LIB file, DLL file and header file. You will need to include the libusb header file in your source project. Then under your project settings you should go to the Linker section and add the LIB file as a linked object. Then, just ensure your DLL is accessible to your executable when running or debugging.

Eclipse: Add external lib for c project Not working

I have done the following:
Create new c project (Makefile Project with Existing Code)
Added a build variable that my Makefile complained about
Now my source .c file complains about #include files because it does not know where the lib folder is,I tried adding lib folder to library path (DID NOT WORK).
How can I link my project to an external lib folder so that my .c source file can read the .h files needed for the #include?
I added the library path to Paths and Symbols->Includes BUT when I go back to the project it only shows the root folder and nothing inside it. Do I also have to add each individual .so lib file?
Answered here : How do you add libraries to Eclipse CDT? (No such file or directory)
#cyfur01 has the best answer :
What to add depends on what you are trying to include. In the case of
Boost, there are a number of header-only libraries, and there are some
libraries that require linking in static/shared-object libraries
(e.g., serialization). Header-Only Libraries
For header-only libraries, you just need to include the base directory
of all the header files. With gcc, you add the directory using the -I
flag (e.g., -I C:/path/to/boost_52_0). With a managed makefile project
in Eclipse, you can accomplish the same using Properties > C/C++ Build
Settings > Tool Settings > GCC C++ Compiler > Directories Static/Shared-Object Libraries
For static/shared-object libraries, you have to specify two options:
-l --> The name of the library, less the 'lib' prefix and the file suffix (e.g., libboost_serialization.dll -> boost_serialization
-L --> The directory to look for the library file in. This is only needed if the library is on a non-standard path.
As #Chris pointed out, for a managed makefile project, both of these
options can be set through Properties > C/C++ Build > Settings > Tool
Settings > GCC C++ Linker > Libraries
ok so I figured it out:
(1) At the start I had a source.c and a MAKEFILE
(2) Create new c project (Makefile Project with Existing Code)
(3) MAKEFILE complained about a variable so I added it to environment variable
(4) #include files complained so I added external library like so
(a) I located my library path and found that there is a folder before /lib called include
(b) The include folder had a list of header files
(c) So I added the path to the include folder NOT the lib folder under paths and symbols include
WORKED LIKE A CHARM!

What is the correct way to add .dll file in a MSVC 2010 project

I need to use the library libMPSSE.dll in my win32 console application project in MSVC 2010. After writing the code I just copied the dll in the folder where my .cpp file is present. I am able to compile successfully but the issue is I am having linking error:
libMPSSE.dll : fatal error LNK1107: invalid or corrupt file: cannot
read at 0x308
Is it really a problem with the dll itself or is there any problem with the dll path. How do we add dll to projects?
They have not provided any .lib file. The complete code is here
These are the usual steps to link to a DLL:
Include the DLL's header file in any of your source files that need to use functions from the DLL. You'll typically need to make sure that your build environment's include path contains the location of the header file. In the IDE you can do this using the Additional Include Directories configuration setting.
Pass the DLL's .lib file to the linker. In the IDE you do this by adding the .lib file to the Additional Dependencies setting. And you'll typically need to add the path to the .lib file to the Additional Library Directories setting.
Having done that, your program should compile and link. To make it run, you'll need to ensure that the DLL itself can be found at runtime. The simplest way to make that happen is to put it in the same directory as the executable file.
My guess, looking at your error message, is that in step 2 you passed the .dll to the linker rather than passing the .lib file.
As said here earlier you can't link to .dll files with C linker directly.
There're win32 APIs that can load the .dll file and return to you pointers to function.
Usually, .dll file is accompanied with .lib file contains code that does this burden for you and provides the API .dll file exposes. All you need is to link to this .lib file and put .dll file near the .exe file created.
Specifically regarding libMPSSE, it's said in its release notes that you can rename the provided .a file to .lib file to link to it in Visual Studio (Project properties->configuration properties->Linker->Input). I tried it and it works as supposed.

How to link a ".so" library in Microsoft Visual Studio

I was wondering if anyone knew how to link a .so dynamic library (or a .a static library for that mater) in Microsoft visual studio. The following steps have not worked for either .a or .so.
I'm playing around with the vs-android plugging to develop in Android NDK using MVS and I'm trying to add a custom library, compiled as a .so, to the project.
1 - I've created a dynamic library (.so) project alongside one of the sample projects (the san-angeles project), in the same solution.
2 - I've set the .so project, let's call it "engine" as a dependency of san-angeles. The engine.so file is generated without any problems, and appears in the {SolutionFolder?}/Android/Debug folder.
3 - I've added engine.so to the linker additional includes of san-angeles and the {SolutionFolder?}/Android/Debug folder (as a full path, something like C:/projects/.../Debug) to the additional linker directories.
But when I compile san-angeles I get the error:
"arm-linux-androideabi-g++.exe: engine.so: No such file or directory"
So I'm guessing I need to do something else to add a .so/.a to a project? Maybe change the name to libengine.so or something like that? A lot of the default includes have the lib prefix, so I don't know if it's something along those lines.
Thank you for the help,
Jaime
For anybody stumbling on this problem:
Add the directory where the .so resides in Linker -> General -> Additional Library Directories. The project you are compiling must be also a Dynamic Library .so for the linker to be available. This appends the -L flag to the commandline
In the Linker -> Command Line append your .so to the Additional Options with the -l flag with quotes, e.g. -l"MyDynamicLibraryWithoutLibPrefixAndExtension". In my case I wanted to link libassimp.so -> -l"assimp"
Ok, so in my case this was solved by:
1 - Naming the generated engine.a as libengine.a
2 - Instead of, from MVS, adding engine.a to Preferences/Linker/Additional Dependencies, I added to Preferences/Linker/Command Line -l"engine"
With this, the project finally managed to find and engine.a
Hope this helps someone else. :)

How to use igraph (and other libraries) in Visual Studio 2010 for C?

I just started C recently and have been writing some basic C code, but is a bit clueless about how I should go about "installing" libraries like igraph in Visual Studio 2010. I downloaded the igraph "source code for Microsoft Visual Studio" here: http://igraph.sourceforge.net/download.html
(naive) Attempt
There is an "include" folder with all the ".h" files that I copied to the directory that my Visual Studio is set up to look in whenever I use include < something.h > but I get a "unresolved external symbol", which I know means the library isn't set up correctly.
Question
How should I go about "installing" igraph? (and possibly other C libraries)
Look in to the folders of your library, I suppose, you'll find a .lib file there.
Go to your project settings and open the linker settings. Under Input you should find additional dependencies. Add your .lib file(s) there. You also might need to add the folder where this .lib file(s) reside to the library folders (found under VC++-folders).
I have the german version of MSVC here, so your menu entries might be named slightly different, but you will find them ;)
Mark's answer was very helpful, but there were other issues. Following these step resolved it for me. Hopefully this will help someone in the future.
Step 1
The igraph package is a bunch of ".c" and ".h" files that was missing the ".lib" file in Mark's answer. It has to be open and build in Visual Studio. Then, the ".lib" file will appear in the "Debug" folder.
Step 2
Do the steps in Mark's answer.
However, in "VC++ Directories" there is a line call "Include Directories" where you have to store the path to your igraph include directory. This is so that Visual Studio can find the correct files when you write e.g. #include <include/igraph.h>.
Step 3
If you get a "...already defined in MSVCRTD.lib..." error. Then, visit this answer: How to resolve the following linker errors in Visual Studio?
Each of the libraries/subprojects that you are using must be compiled with the same option in "C/C++ -> Code Generation -> Runtime library".

Resources