I have two source files, main.cc, foo.cc.
#include <iostream>
using namespace std;
int main() {
cout << "main\n";
}
foo.cc
#include <iostream>
using namespace std;
class foo {
public:
foo() {
cout << "foo ctor\n";
}
};
static foo foo_obj;
When I manually compile like this:
$ g++ -c foo.cc -o libfoo.a
$ g++ main.cc libfoo.a -o main
$ ./main
foo ctor
main
But when I use cmake, it won't print foo ctor
. Here's the CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_FLAGS "-std=c++11")
add_library(foo STATIC foo.cc)
add_executable(main main.cc)
target_link_libraries(main foo)
Obviously cmake has done something that I don't expect.