visual c++ - C++ Include Confusion -
i have following issue c++ application (i'm starting out c++).
i'm sure relates includes in way, believe correctly using include guards, not sure else can do.
example:
if declare following header file function body in header file, application compiles , runs expected. if split out separate .h , .cpp files however, build fails error copied @ end of post. i'd correctly separate implementation header understand a) correct way , b) results in faster builds.
i have included screenshots configuration properties > linker > input , general > use of mfc have had changed during project build satisfy requirements (i need use "use mfc in static library").
so, how can split files out , not have build fail? thanks.
json_ops.h (all in header file)
#ifndef json_ops_h #define json_ops_h #include "stdafx.h" #include "../srclib/rapidjson/document.h" namespace cdm_data_distributable { class json_ops { public: void test_json() const; }; void json_ops::test_json() const { // json parsing example const char json[] = "{ \"hello\" : \"world\" }"; rapidjson::document d; d.parse<0>(json); } } #endif
json_ops.h, json_ops.cpp (separate files)
header file
#ifndef json_ops_h #define json_ops_h #include "stdafx.h" #include "../srclib/rapidjson/document.h" namespace cdm_data_distributable { class json_ops { public: void test_json() const; }; } #endif
.cpp file
#include "json_ops.h" namespace cdm_data_distributable { void json_ops::test_json() const { // json parsing example const char json[] = "{ \"hello\" : \"world\" }"; rapidjson::document d; d.parse<0>(json); } }
resulting errors
error lnk1169: 1 or more multiply defined symbols found "void * __cdecl operator new(unsigned int)" (??2@yapaxi@z) defined in libcmtd.lib(new.obj) "void __cdecl operator delete(void *)" (??3@yaxpax@z) defined in libcmtd.lib(dbgdel.obj) c:\svn\cdmdatacds\application\cdmdatadistributable.ui\uafxcwd.lib(afxmem.obj) cdmdatadistributable.ui
it looks using pre-compiled headers; need include stdafx.h in every cpp file. add #include "stdafx.h"
line in cpp, before #include "json_ops.h"
.
if json_ops.h
included elsewhere, stdafx.h
won't included systematically json_ops.cpp
file.
Comments
Post a Comment