i have just found out that Code Blocks (and MingW compiler) only takes .a library files rather then .lib what is the easiest way to convert .lib to .a files... any tutorials etc would be appreciated. Edit let me modify my question slightly how can you convert numerous source files into one .a archive file.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
The .lib (and .a also) works under two different capacities:
You didn't really specify in your question which form you're working with. If you're looking to do the second form, you'll have to build the source under gcc as a static library as suggested by Persson since the library format used by msvc tools aren't compatible.
However, there's some good news if you're working with the first form. The MinGW port of gcc should be able to work transparently with a coff-format import library created with msvc development tools. What you can do is simply rename the
*.lib
import intolib*.a
and just pass that to the linker like it's any other*.a
file. The linker should be able to sort out its real format.I've tested this under tdm-gcc-4.5.2 with the latest nightly build of codeblocks and it appears to work ok.
Edit: Merged my comment as part of the answer. If you're working with the second form and need to build a static library from source, the steps are roughly as follows:
If there's an existing msvc project you can use it as a starting point by importing it into codeblocks. It'll be under File->Import Project->Visual Studio etc.
If none is available making a new C::B project from scratch isn't too difficult. Just goto File->New->Project select 'Static Library' as the project type then add whatever source file is needed. If the library is written in a semi-portable matter it should compile without too much trouble.
MinGW can use .LIB files. The following links to a .LIB created with the MS compiler:
In codeblocks, you add the library in the dialog
Project|Build Options...
and then go to theLinker Setting
s tab and add to theLink Libraries
box.To answer the specific question, how to convert several source files into a single archive file for static linking; it is a two step operation. You must first compile the source files into object files, followed by turning the object files into an archive.
If you have MSYS with your MinGW installation, I recommend using that. If not, you can still use Windows' command prompt cmd.exe.
Make sure your MinGW/bin directory is part of the PATH environment variable so you can invoke the compiler from anywhere.
From the command line, move into the directory that holds the source code. From there, type the command
You should either name the
[files]
specifically,-c a.cpp b.cpp c.cpp
or you can identify them all with*.cpp
.[header directory]
is where the .h files for the source are, relative to you. Generally, source files will be in a directory by themselves called /src, and header files in a sister directory called /include. You would refer to that directory as-I../include
. If the header files are in a directory called /include within the /src directory, it would be-Iinclude
.Once you have generated the .o files, you type the command
Replace
[something]
with the name of the library. This is the name that will go in the Link Libraries dialog in Code::Blocks. Files is either the name of the object files you created before (a.o, b.o, c.o) or, if there are no unrelated object files in the directory, you can put in*.o
.That should result in the archive file being created within the directory. You can now place it in the proper directory (possibly a sister directory to /include called /lib), and add that directory to your Code::Blocks configuration, under Linker Search Directories. You must then remember to actually add the library for you project.