I've been able to pinpoint the problem.   The contents of the files A,B,Main (as shown in the image) are as follows:  cmake_minimum_required(VERSION 3.13)  add_library(class_a ${CMAKE_SOURCE_DIR}/modules/class_a/class_a.cpp) target_include_directories(class_a PUBLIC ${CMAKE_SOURCE_DIR}/modules/class_b) target_link_libraries(class_a PUBLIC class_b)  cmake_minimum_required(VERSION 3.13) add_library(class_b ${CMAKE_SOURCE_DIR}/modules/class_b/class_b.cpp)   and  cmake_minimum_required(VERSION 3.13)  add_executable(test_class_a test_class_a.cpp) target_include_directories(test_class_a PUBLIC ${CMAKE_SOURCE_DIR}/modules/class_a/) target_link_libraries(test_class_a PUBLIC class_a)   The classes have their own *.hpp and *.cpp files (the first two are the *.cpp-files with definitions, and the last is the test_class_a.cpp:  #include "class_a.hpp" #include "class_b.hpp"  template&lt;typename t&gt; class_a&lt;t&gt;::class_a() : field(42) {} template&lt;typename t&gt; class_a&lt;t&gt;::~class_a() { field^= field; }  template&lt;typename t&gt; void class_a&lt;t&gt;::do_it() {     class_b&lt;t&gt; b;     b.do_something(); }  #include "class_b.hpp" template&lt;typename t&gt; class_b&lt;t&gt;::class_b() { info= {}; }; template&lt;typename t&gt; void class_b&lt;t&gt;::do_something() { return ; }  #include &lt;memory&gt; #include "class_a.hpp"  int main() {     auto ptr= std::make_unique&lt;class_a&lt;int&gt;&gt;();     ptr-&gt;do_it();     return 0; }   I read elsewhere that this is always the problem with templates and unique_ptr, and one of the solutions is to put everything into a single file, without separating the header and definitions. I wonder if this is the only way, or is there some CMake-way of keeping the same structure and modularity, and still being able to compile? The above code gives the compile error:  [ 33%] Built target class_b Scanning dependencies of target class_a [ 50%] Building CXX object modules/class_a/CMakeFiles/class_a.dir/class_a.cpp.o [ 66%] Linking CXX static library libclass_a.a [ 66%] Built target class_a Scanning dependencies of target test_class_a [ 83%] Building CXX object modules/tests/CMakeFiles/test_class_a.dir/test_class_a.cpp.o [100%] Linking CXX executable test_class_a /usr/bin/ld: CMakeFiles/test_class_a.dir/test_class_a.cpp.o: in function `main': /home/ilo/CLionProjects/mwe/modules/tests/test_class_a.cpp:6: undefined reference to `class_a&lt;int&gt;::do_it()' /usr/bin/ld: CMakeFiles/test_class_a.dir/test_class_a.cpp.o: in function `std::_MakeUniq&lt;class_a&lt;int&gt; &gt;::__single_object std::make_unique&lt;class_a&lt;int&gt;&gt;()': /usr/include/c++/8/bits/unique_ptr.h:831: undefined reference to `class_a&lt;int&gt;::class_a()' collect2: error: ld returned 1 exit status make[3]: *** [modules/tests/CMakeFiles/test_class_a.dir/build.make:86: modules/tests/test_class_a] Error 1 make[2]: *** [CMakeFiles/Makefile2:129: modules/tests/CMakeFiles/test_class_a.dir/all] Error 2 make[1]: *** [CMakeFiles/Makefile2:141: modules/tests/CMakeFiles/test_class_a.dir/rule] Error 2 make: *** [Makefile:131: test_class_a] Error 2
Quote from :     The only portable way of using templates at the moment is to implement them in header files by using inline functions.   Why is this?  (Clarification: header files are not the only portable solution. But they are the most convenient portable solution.)
Use Unity API from another Thread or call a function in the main Thread Is it legal to add your publications to ResearchGate? I recently created a profile on . And to add your publications list it requires you to upload the paper. Is it legal to upload published journal articles on public servers, where everyone can download it for free? Efficient online linear regression Bogus float inequality due to compiler optimization? Cannot replace a packed image in the uv image editor I was trying to replace an image in my UV image editor, but the image defaults to a different image. how do I fix this? Is there any software that can easily create a Styled Layer Descriptor (SLD) without using a  script? Why does the series $\sum_{n=1}^\infty\frac1n$ not converge? Difference between "commit suicide" and "suicide" Rendering low and res/high res images Is it possible to render in Blender with reduced low res files and then ask Blender to render the final render with 4k high res files? Low and high res files would be numbered identically but would be located in different folders.  Many thanks Can a creature with blindsight that is not immune to the Blinded condition suffer the effects of Blindness? Is there even an automatic ban on meta? Somewhere I heard the automatic question ban on Meta is set lower than on the main site. But looking at the profile of  it looks like there is absolutely no automatic ban on meta.  Is this intended behaviour? A method for the OP to accept comments? Question: What if the author of a question can accept a comment?   The problem:  Time and time again, answers are posted as a comment.  Usually, the person who commented has the best of intention (e.g. it was a trivial answer [to the answerer], and they weren't sure if the OP would immediately edit the question after the comment).  But this leaves the frustrating situation of an unanswered question with a perfectly good answer.  This problem accumulates over the years.     Candidate solution:  The OP can just "accept" the comment, after which a duplicate of the comment is made an accepted CW answer, with a preface indicating that it was originally a comment, e.g. This answer was originally a comment posted by [[blah]] that has been accepted by the author of the question.   Comments on this scheme:   The author of the comment has indicated they're not interested in gaining/losing reputation through their comment (thus CW answer). The original comment is still there. If desirable, the "author" of the accepted question could be a "bot", so the answer is not attributed to a genuine account.  (I suppose it would already be technically possible for Joe Blow to create a script for a bot that creates an answer from a comment in the proposed way.)     A similar question was asked before  (over 3 years ago), and in numerous other questions which have been deemed "duplicates" (,  and ; see also ), so there seems to be demand for such a feature.  The answers to these questions seem (to me, at least) quite weak:   "ask the commenter to add the comment as an answer"   The OP already did this by asking the question in the first place.  And what if the author of the comment doesn't respond (or takes a long time to respond)?  This also adds more chit-chat irrelevant to the question.   "add an answer of your own, referring to the comment, and accept it."   A hacky workaround.  How could this possibly be better than accepting a comment?  (Yet, this is the most up-voted response.)  Moreover, this adds to the user's list of "answers" (thus making the user's page harder to look through).   "When i leave a comment, i do so because i want to leave a comment."   Great; now what about everyone else?  In the immortal words of the FAQ: "Other people can edit my posts?!"  And it's not even an edit, it's copying the post from one box to another (a more hacky version of which is regarded as the "accepted" method). Theoretically possible to run two operating systems simultaneously? A friend of mine asked a question that got me thinking. Is it possible (theoretically, I assume it hasn't been done) to run two operating systems simultaneously on the same computer? Not in the sense of multitasking in one window, but being able to quickly switch from one to the other without restarting. Could something low-level be created that would intercept system calls (or whatever needs to be done) to make each OS think it is running alone? Or hardware itself that would accomplish this?  I'm not talking about dual booting or using virtual machines, but actually running two OS's side-by-side. Addition is to Integration as Multiplication is to ______ How do you remove duplicates from a list whilst preserving order? Is there a built-in that removes duplicates from list in Python, whilst preserving order? I know that I can use a set to remove duplicates, but that destroys the original order. I also know that I can roll my own like this:  def uniq(input):   output = []   for x in input:     if x not in output:       output.append(x)   return output   (Thanks to  for that .)  But I'd like to avail myself of a built-in or a more Pythonic idiom if possible.  Related question: Short-cut for switching to a given directory How can I find a saved Wi-Fi password? I have an Android phone which is connected to a secured Wi-Fi hotspot.  How can I find out the password of the hotspot from the phone? Building where clause based upon parameters Manganese has more unpaired electrons than Iron so why is Iron ferromagnetic Manganese paramagnetic? Manganese has five unpaired electrons, but Iron has four, then why is Iron ferromagnetic and Manganese paramagnetic? What's that property I'm missing? Does the diameter of the aperture increase with increases in the focal length with constant F-number(F-stops)? What I have learned from the definition of F-number is that;  The F-number (sometimes also called focal ratio, f-ratio, f-stop, or relative aperture) of a lens is the ratio of its focal length divided by the diameter of the aperture. And F-numbers are expressed as f/1, f/1.4, f/2, f/2.8, f/4, f/5.6, f/8, f/11, f/16, f/22, f/32 etc. Hence F-number (F-stop) depends on two variables; that are diameter of aperture and focal length of the lens.  Aperture diameter/size is one of the component which governs the amount of light that enters to the camera. As far as I known, at different F-stops values (f/1, f/1.4, f/2, f/2.8, f/4, f/5.6, f/8, f/11, f/16, f/22, f/32) the amount of light allowed to enter the camera is fixed and are with either 1/2 or 1/3 stop increment.  This concept is very easy to understand, in case of prime lenses (with a  fixed focal length and variable aperture), where F-stop is inversely proportional to the aperture diameter. For lower F-number (F-stop) the aperture would be bigger allowing more light and for higher Hence F-number (F-stop) the aperture would be smaller allowing less light in to the camera.  F-numbers (F-stops) have been evolved to allow a definite/fixed amount of light in to the camera (As far as I known). In case of zoom lens (with variable aperture and variable focal length), I am not able to understand the what would be the relationship between F-stop and the diameter/area of aperture at different focal length.  I have two related questions  1 . In case of zoom lens,  for example, Canon EF-S 18-135mm f/3.5-5.6  (with variable aperture and variable focal length). At any particular F-number(F-stop), for example at f/5.6 , does the diameter of the aperture increase with increases in the focal length? I mean,  Is the diameter of the aperture at  18mm and f/5.6 would be smaller than that of at 135 mm and f/5.6?   In the above case (i.e. Canon EF-S 18-135mm f/3.5-5.6 ), What is amount of light that would enter the camera at 18mm and f/5.6 compared to that of at 135 mm and f/5.6? Will the amount of lights be same or different?