I am trying to test out a new library I just made and I keep getting errors. The library contains a template class named nstack and the main file is called test.cpp. I have tried using the test funtion withing nstack.cpp and it works, but when I move it to it's own file, it won't link correctly. I have nstack.h included in both files (and it does exist, I'm not an idiot), and this is the only error:
test.cpp:(.text+0x8b) undefined reference to 'nstack%26lt;char%26gt;::nstack()'
This appears for any nstack functions I call.
I use g++ on a linux machine, and here is what I type to compile:
g++ test.cpp nstack.cpp -o nstack
Any ideas?
C++ multiple files?
You did code the (whole) template in the nstack.h header file, right? If part of it is in the cpp file that would explain why it compiles with a main() in it but not when main() is moved to another source file.
Reply:The issue is somewhat complicated to explain. Suffice it to say that you probably want to keep your header and implementation all in the header file.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment