I have a program and a static library:
// main.cpp
int main() {}
// mylib.cpp
#include <iostream>
struct S {
S() { std::cout << "Hello World\n";}
};
S s;
I want to link the static library (libmylib.a
) to the program object (main.o
), although the latter does not use any symbol of the former directly.
The following commands do not seem to the job with g++ 4.7
. They will run without any errors or warnings, but apparently libmylib.a
will not be linked:
g++ -o program main.o -Wl,--no-as-needed /path/to/libmylib.a
or
g++ -o program main.o -L/path/to/ -Wl,--no-as-needed -lmylib
Do you have any better ideas?
ar
– Intosh