My C++ class is having trouble linking to a function in another .cpp file

后端 未结 2 1265
北海茫月
北海茫月 2021-01-16 06:04

I asked the same question yesterday and the answer was not applicable.

https://stackoverflow.com/questions/6194578/breaking-up-class-functions-into-multiple-cpp-files

2条回答
  •  無奈伤痛
    2021-01-16 06:21

    This has nothing to do with includes. What you have there is a linker error. Includes are all about compilation, which requires the declarations of identifiers referred to.
    The error you have means that the linker can't find the definition of a function in any of the object files passed to it which is called by one or more of them. (See this answer for what's a declaration and what's a definition and what they are needed for.)

    You need to pass to the linker the object files created from compiling all of your .cpp files. If you're using some sort of an IDE, it should do this for you if you add all .cpp files to your project. If you're using a makefile, list all .cpp files as dependencies of your target. If you compile by invoking the compiler manually (which then calls the linker), pass all .cpp files to it in the same invocation.

提交回复
热议问题