main.cpp.o: In function std::iterator_traits<unsigned char const*>::iterator_category std::__iterator_category<unsigned char const*>(unsigned char const* const&)': subprocess.hpp:152: multiple definition ofsubprocess::util::quote_argument(std::basic_string<wchar_t, std::char_traits, std::allocator > const&, std::basic_string<wchar_t, std::char_traits, std::allocator >&, bool)'
main.cpp.o:/subprocess.hpp:152: first defined here
helper.cpp.o: In function std::vector<char*, std::allocator<char*> >::reserve(unsigned int)': /subprocess.hpp:152: multiple definition ofsubprocess::util::quote_argument(std::basic_string<wchar_t, std::char_traits, std::allocator > const&, std::basic_string<wchar_t, std::char_traits, std::allocator >&, bool)'
main.cpp.o:/subprocess.hpp:152: first defined here
collect2: error: ld returned 1 exit status
Solution
This is easily solved by changing void quote_argument(const std::wstring &argument, std::wstring &command_line, bool force) to inline void quote_argument(const std::wstring &argument, std::wstring &command_line, bool force)
My code is set up as follows:
main.h
helper.h
helper.cpp
Error:
Because of this, I get:
main.cpp.o: In function, std::allocator > const&, std::basic_string<wchar_t, std::char_traits, std::allocator >&, bool)'
main.cpp.o:/subprocess.hpp:152: first defined here
helper.cpp.o: In function , std::allocator > const&, std::basic_string<wchar_t, std::char_traits, std::allocator >&, bool)'
main.cpp.o:/subprocess.hpp:152: first defined here
collect2: error: ld returned 1 exit status
std::iterator_traits<unsigned char const*>::iterator_category std::__iterator_category<unsigned char const*>(unsigned char const* const&)': subprocess.hpp:152: multiple definition of
subprocess::util::quote_argument(std::basic_string<wchar_t, std::char_traitsstd::vector<char*, std::allocator<char*> >::reserve(unsigned int)': /subprocess.hpp:152: multiple definition of
subprocess::util::quote_argument(std::basic_string<wchar_t, std::char_traitsSolution
This is easily solved by changing
void quote_argument(const std::wstring &argument, std::wstring &command_line, bool force)
toinline void quote_argument(const std::wstring &argument, std::wstring &command_line, bool force)
* Filenames changed for privacy.