I have Visual Studio 2008, Windows7 64 bit.
I am using WinBGIm Graphics Library.
This library is supplied with some .obj files. There are no .lib or .dll files.
I want to convert them into static .lib and dynamic .dll files.
I have copied all .obj files in the directory:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64
But, the following command is not working:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64>lib.exe /out:bgiout.lib *.obj
Microsoft (R) Library Manager Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
LINK : fatal error LNK1104: cannot open file 'bgiout.lib'
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64>
How to do that?
Static libraries are created using some type of archiving software, such as ar. ar takes one or more object files (that end in .o), zips them up, and generates an archive file (ends in . a) — This is our “static library”. Now that we have the object file(s), we can archive them and make a static library using ar.
Go to project properties then from "Property Page" select the node "C/C++" their you will get "Additional Include Directories" add the name of your object file. Keep your obj file in the directory where your source code is or you can add the directory from: Tools->Options->Projects and Solutions->VC++Directories .
In other words, the “ar” command can be used to create a static library, to add and to modify object files already included in the library. The object files included in the static library can then be listed via the following command line: “ ar -t libstatic_library.
Yes you can do that, pretty much just as you have it.
C:\Code\bgi\obj>lib /out:libbgi.lib *.obj
LIB (lib.exe) is used to create static libraries. LINK (link.exe /DLL) is used to create dynamic libraries (it creates the .dll and an import library .lib).
C:\Code\bgi\obj>link /DLL /out:bgi.dll *.obj [additional libs]
When using the link /DLL
command, additional Win32 and C++ standard runtime libraries will be required (such as MSVCRT.lib and User32.lib etc. and MFC libraries).
In this case; this seems to be the correct linker arguments;
C:\Code\bgi\obj>link /DLL /out:bgi.dll *.obj MSVCRTD.lib User32.lib Gdi32.lib ole32.lib Comdlg32.lib OleAut32.lib
Note: the object files built are debug versions, hence MSVCRTD.lib (note the D) is the one to use here. With the commands above, I've been able to successfully link both a .dll and a static .lib.
Additional include and library paths;
When distributing these outputs for other builds additional header and library paths may need to be included into the target build. To add additional locations to the include and library search paths, the environment variables (INCLUDE
and LIB
) can be added to (either per user or system wide), but these can also be specified on the command line, via /I
and /LIBPATH
as follows;
cl /IC:\Code\include [additional options] main.cpp
link /LIBPATH:C:\Code\lib [additional options] xyz.lib
Guidelines;
Your error LNK1104
I suspect the error you have, LNK1104, is most likely because your user does not have sufficient permission to be writing files within the "Program Files" directory. Else, it may be an error with using the incorrect toolchain for your target (x86 vs. x64).
It is generally better to do this in a directory of your own; e.g.: "C:\Code\bgi".
Modern C++ compilers will embed information about the libraries they need. For visual studio, a .obj file includes a reference to the C++ libraries it relies on (/MT /MD /MTd /MDd) these libraries have slightly different implementations, and are not compatible with them. The only choice is to have source code, or multiple .obj files for each supported build mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With