I wanted to learn how to use a .lib file in my C application.
So, I followed these steps:
Created a empty project in VC++,
Added a .c file,
Added few c functions,
Created a .h file for the same,
Changed the projects type to .lib
Built the project.
No problem till here.
Now,
I copied the .h and the .lib file to desktop,
created another VC++ empty project of type .exe,
In poject prop.->config. prop.->c/c++->additional include directories,I added the path to desktop,
In poject prop.->config. prop.->linker->additional library dependencies,I added the path to desktop,
building the project gives LNK2019 (unresolved external symbol _...) and fatal error LNK1120 (unresolved external symbols).
What am I doing wrong? Also what would be the steps to use a .dll instead of .lib?
Configuration: Windows 7, VS2008.
You also have to add the library by name to the list of Additional Dependencies in Linker->Input options for your Project.
Do you really want this linked in from the desktop, by the way? Typically some project-relative path or environment variable would be the way to do this - you do not want to link from desktop on a build server, for example.
Switching to a DLL will not help because you still need to use the export library (.LIB) file for your DLL to satisfy the link-time dependencies.
Related
When I am trying to access files from standard usr/ it is not working. and showing errors that file is missing .
I have added path but and make it work but i think this is not the correct way.
I have a workspace with 10-12 projects which are of c and cpp both.
In one project I am using cpp with thrift libraries and protocol.
in that project only I am facing issue. with I am individually building that project it is working but when building it from the main project. it starts showing error in files.
There all almost 17 projects and 16 are generating .so files and all are going to the main project. and main is generating an executable. and that executable uses all the .so files.
but In thrift only it is showing errors. before it was showing for #include i added that file so now it is showing undefined type Name Space ..
I think this issue is because of relative path but I am not sure
Please Help
I am trying to get an open source software called AuBio ( Source ) to run on Visual studio express but I am having a lot of problems getting it to build.
What I've Done:
I opened a new C/C++ solution on VS Express then copied all the header files in the source folder (SRC) into the "Header Files" filter of my project then copied all the C files in the SRC folder into the "Source Files" filter of my project. I have also downloaded all the 3 dependencies required to run AuBio but I do not know where to put them because the "External Dependencies" filter of my project does not seem to want accept them.
Can someone please guide me on how I can go about about building this program?
Addition:
The dependencies are other open source projects; the build instructions for AuBio ( which are HERE ) tell me that I need to install the dependencies before I use AuBio but I have no clue how I can do that.
AuBio also provides a pre-compiled version of it's software (it's cross compiled on MingGW32, and is here) which consists of exe files for each major class and dll files for both AuBio and all it's dependencies, but I have no idea how to use these too, when I download and try to run the exe's they refuse to run.
I am really stuck on this can someone help?
It's not clear what you mean by filter. Do the header files and source files appear in 'Solution View' of the project? If not you need to add them to the project using the Project, Add Existing Item menu command.
Dependencies:
If they are .lib files then add a line like this to your source files:
#pragma comment (lib,"libname.lib")
We made an Eclipse CDT plugin in order to create a C project layout that follow certain standard set across our organization. We maintain some sort of XML files that define the project/product dependencies. That means, every product will have an XML file that defines what source files/headers goes into that product.
So, when importing a C project in Eclipse CDT, instead of following the standard CDT project setup, our plugin takes product name as the input and parses the product's XML to generate a C project with appropriate source files.
We were able to attach source files to the C project using the following API and Linked Resources concept in Eclipse.
org.eclipse.core.resources.IFolder
org.eclipse.core.resources.IFile
We were also able to attach header files to the same C project using the following class.
org.eclipse.cdt.core.model.IIncludeEntry
Note: We created IIncludeEntry instances with the inlcude directories
as the input. Eclipse's scanner discovery mechanism is identifying the
individual source files inside each directory and showing them under
"Includes" tag in C project.
Now the source files are shown under "Source" tag and the header files are shown under "Includes" tag in the C project. We could modify and build the source files without any issues.
However, we couldn't edit any of the header files. If I manually add an external header file thru Project >> Properties >> C/C++ General >> Paths and Symbols everything works fine, we can edit the files.
I also tried to use org.eclipse.cdt.core.model.IIncludeFileEntry instead of IIncludeEntry by giving individual header file paths to IIncludeFileEntry. But Eclipse isn't identifying anything with IIncludeFileEntry.
What's the CDT API to create/attach header files to a C project? How Eclipse CDT creates them?
I have a project which I try to compile with Eclipse-CDT. The project depends on a library with header files and source files. How can I configure the project in Eclipse such that it will compile the needed source files from the library with the project?
With a makefile I use:
SRC+=lib_source.c
You can add linked source file.
Choose project properties and in the left panel choose c++ general.
Under it choose path and symbols.
Now in the right panel tabs choose source location and add linked source folder.
Include you need to define in "include" (under c++ build you will find settings)
Another approach is to use the operating system to add your libraries to the project. Eclipse then treats all source files (including library files) as part of the project, and therefore compiles any that need it even if they are in the libraries. This set-up allows keeping the library sources in a separate git repository from the project source code. You can record the git commit of a library to provide library version control so that improving the library in one project does not break all the others. The setup relies on the operating system's capability to link directories in a way that is entirely transparent to eclipse--in windows using the mklink command.
In windows the steps are
put your library files in a clean workspace not mixed with .git (you can have .git in the parent directory as egit sets it up)
use cmd window in administrator mode to add a link from your project directory to your library directory.
from eclipse press F5 t make sure your project matches what is on disk, then set up git to ignore your library directory.
set up your library file properties for read only access unless you are still tweaking that library.
set up your project include path to include the project sub-directory in your project.
I can't remember why I abandoned eclipse linked directories; i think it was that the includes kept breaking. The mklink approach has worked flawlessly so far.
I have a pdf tutorial of how to set this up--but I'm new to the forum and don't see how to attach a file.
Using visual studio 2008, I have an .H and a .LIB file of a library.
I wrote a program and referenced the LIB via the project properties.
It compiles fine, but when it runs, it asks for the DLL to be installed.
If the DLL is in the same dir as the EXE it works but, if I have the LIB, doesn't it already mean the functions are statically linked to my program?
Not all lib files are static libraries. Some are import libraries, and chances are, that's what you linked with.
If your lib file is much smaller than its corresponding dll file, that's a sure sign that it's an import library.
Letting your program use a DLL requires an import library. It is a file with the .lib extension, just like a static .lib. But it is very small, it only contains a list of the functions that are exported by the DLL. The linker needs this so it can embed the name of the DLL in the import table. You can see this for yourself by running Dumpbin.exe /imports on your .exe