Opened 15 years ago

Closed 15 years ago

#995 closed Bugs (fixed)

'multiply defined symbols' when including <boost/filesystem.hpp> in different source files

Reported by: anonymous Owned by: Beman Dawes
Milestone: Component: filesystem
Version: Boost 1.34.0 Severity: Problem
Keywords: Cc:

Description

When <boost/filesystem.hpp> is included in different source files, the linker complains about 'multiply defined symbols'

Attached: two source files that reproduce the error when compiled and linked in the same project.

boost-1.34.0 MSVC 7.0

test2.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl boost::filesystem::extension(class boost::filesystem::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem::path_traits> const &)" (?extension@filesystem@boost@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$basic_path@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Upath_traits@filesystem@boost@@@12@@Z) already defined in test.obj
test2.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl boost::filesystem::basename(class boost::filesystem::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem::path_traits> const &)" (?basename@filesystem@boost@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$basic_path@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Upath_traits@filesystem@boost@@@12@@Z) already defined in test.obj
Release/test.exe : fatal error LNK1169: one or more multiply defined symbols found

Attachments (2)

test.cpp (63 bytes ) - added by anonymous 15 years ago.
first file
test2.cpp (33 bytes ) - added by anonymous 15 years ago.
second file

Download all attachments as: .zip

Change History (9)

by anonymous, 15 years ago

Attachment: test.cpp added

first file

by anonymous, 15 years ago

Attachment: test2.cpp added

second file

in reply to:  description comment:1 by anonymous, 15 years ago

Workaround (works for MSVC 7.0):

add "/force:multiple" to advanced linker options

comment:2 by frederic.bron@…, 15 years ago

There is an "inline" missing in filesystem/convenience.hpp

# define BOOST_FS_FUNC_STRING std::string

should be

# define BOOST_FS_FUNC_STRING inline std::string

comment:3 by Eric Niebler, 15 years ago

Owner: set to Beman Dawes

comment:4 by mkl, 15 years ago

Oh, the fix didn't make it into 1_34_1 :(

comment:5 by Benjamin Eikel, 15 years ago

This problem exists with mingw/gcc too. But the suggested workaround works.

comment:5 by Benjamin Eikel, 15 years ago

This problem exists with mingw/gcc too. But the suggestes workaround works.

comment:7 by Beman Dawes, 15 years ago

Resolution: fixed
Status: newclosed

(In [38567]) Fix #995 by adding inline

Note: See TracTickets for help on using tickets.