Created
July 19, 2018 04:29
-
-
Save morrisonlevi/b1508531b1464921664ca06c0fd889bb to your computer and use it in GitHub Desktop.
CMake 3.12: Transitive OBJECT Libraries issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "box.hh" | |
template class box<int>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef BOX_HH | |
#define BOX_HH 1 | |
#include <utility> | |
template <class T> class box { | |
T item_; | |
public: | |
box(T t) : item_{std::move(t)} {} | |
~box() = default; | |
T get() const { return item_; } | |
}; | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ 75%] Linking CXX executable main | |
/zapps/cmake/3.12.0/gcc-7.3.0/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1 | |
/apps/gcc/7.3.0/bin/c++ -g CMakeFiles/main.dir/main.cc.o CMakeFiles/make_box.dir/make_box.cc.o -o main | |
CMakeFiles/main.dir/main.cc.o: In function `main': | |
/fslhome/levijm/compute/cmake-3.12-issue/main.cc:9: undefined reference to `box<int>::get() const' | |
CMakeFiles/make_box.dir/make_box.cc.o: In function `make_box(int)': | |
/fslhome/levijm/compute/cmake-3.12-issue/make_box.cc:6: undefined reference to `box<int>::box(int)' | |
collect2: error: ld returned 1 exit status | |
make[2]: *** [main] Error 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.12) | |
project(objectlib LANGUAGES CXX) | |
add_library(box OBJECT box.cc box.hh) | |
add_library(make_box OBJECT make_box.cc make_box.hh) | |
target_link_libraries(make_box PUBLIC box) | |
add_executable(main main.cc) | |
target_link_libraries(main PUBLIC make_box) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "box.hh" | |
#include "make_box.hh" | |
extern template class box<int>; | |
int main() { | |
box<int> b = make_box(0); | |
return b.get(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "make_box.hh" | |
#include "box.hh" | |
extern template class box<int>; | |
box<int> make_box(int i) { return box<int>{i}; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAKE_BOX_HH | |
#define MAKE_BOX_HH 1 | |
#include "box.hh" | |
extern template class box<int>; | |
box<int> make_box(int i); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment