osx - C++ duplicate symbols -


(mac)

i've tried namespaces, include guards, pragma once, etc.

basically, structure:

cmakelists.txt

add_executable(game game/main.cpp game/rtexture.cpp) 

game/main.cpp

#include "cleanup.h"  //... cleanup(foobar); 

game/rtexture.cpp

#include "cleanup.h"  //... cleanup(foobar); 

cleanup.h

//various includes  template<typename t, typename... args> void cleanup(t *t, args&&... args){     //cleanup first item in list     cleanup(t);     //recurse clean remaining arguments     cleanup(std::forward<args>(args)...); } /*  * these specializations serve free passed argument , provide  * base cases recursive call above, eg. when args single item  * 1 of specializations below called  * cleanup(std::forward<args>(args)...), ending recursion  * make safe pass nullptrs handle situations  * don't want bother finding out values failed load (and null)  * rather want clean , let cleanup sort out  */ template<> void cleanup<sdl_window>(sdl_window *win){     if (!win){         return;     }     sdl_destroywindow(win); } template<> void cleanup<sdl_renderer>(sdl_renderer *ren){     if (!ren){          return;     }     sdl_destroyrenderer(ren); } template<> void cleanup<sdl_texture>(sdl_texture *tex){     if (!tex){         return;     }     sdl_destroytexture(tex); } template<> void cleanup<sdl_surface>(sdl_surface *surf){     if (!surf){         return;     }     sdl_freesurface(surf); } 

if asks, did take "cleanup.h" tutorial can't find way include in multiple classes without having declare duplicate symbols.

home @ cruz45488-y19-mba13-12 in ~/desktop/sdlworkspace/tmp $ make linking cxx executable game duplicate symbol __zn5rutil7cleanupi10sdl_windowjeeevpt_dpot0_ in:     cmakefiles/game.dir/game/main.cpp.o     cmakefiles/game.dir/game/rtexture.cpp.o duplicate symbol __zn5rutil7cleanupi12sdl_rendererjeeevpt_dpot0_ in:     cmakefiles/game.dir/game/main.cpp.o     cmakefiles/game.dir/game/rtexture.cpp.o duplicate symbol __zn5rutil7cleanupi11sdl_texturejeeevpt_dpot0_ in:     cmakefiles/game.dir/game/main.cpp.o     cmakefiles/game.dir/game/rtexture.cpp.o duplicate symbol __zn5rutil7cleanupi11sdl_surfacejeeevpt_dpot0_ in:     cmakefiles/game.dir/game/main.cpp.o     cmakefiles/game.dir/game/rtexture.cpp.o 

any help? thanks.

explicit function template specialisations subject 1 definition rule, regular functions are. add inline allow definitions in header; or define them in source file, declarations in header.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -