Bug #1285
converter template class breaks linking on windows
Status: | Resolved | Start date: | 12/07/2012 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | J. Wienke | % Done: | 100% | |
Category: | C++ | |||
Target version: | rsb-0.7 |
Description
This happens on windows when the protocol buffer converter is used in the client code:
boost::shared_ptr< rsb::converter::ProtocolBufferConverter<rst::generic::ListFloat> > converter(new rsb::converter::ProtocolBufferConverter<rst::generic::ListFloat>()); rsb::converter::converterRepository<std::string>()->registerConverter(converter); try { occFieldsInformer = factory.createInformer<rst::generic::ListFloat>(rsb::Scope(outScopeOccupiedFields)); fixatedFieldInformer = factory.createInformer<string>(rsb::Scope(outScopeFixatedField));
Error 58 error LNK2005: "public: virtual __thiscall rsb::converter::Converter<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::~Converter<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??1?$Converter@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@converter@rsb@@UAE@XZ) alreadydefined in rsbcore.lib(rsbcore.dll) C:\isy\ChessBoardFinder\build\ResultPublisher.obj ChessBoardFinder
Associated revisions
Prevent linking errors on windows with the ProtocolBufferConverter.
Due to extending Convert<string> multiple conflicting template instatitation from the Converter base class could occur if the ProtocolBufferConverter was used across multiple compilation units.
- Added a test case to reproduce the behavior
- Added dll import statements to prevent the bug
Merge branch 'bug-1285'
refs #1285
Backport: Prevent linking errors on windows with the ProtocolBufferConverter.
Due to extending Convert<string> multiple conflicting template instatitation from the Converter base class could occur if the ProtocolBufferConverter was used across multiple compilation units.
- Added a test case to reproduce the behavior
- Added dll import statements to prevent the bug
fixes #1285
Fix further compilation errors on windows.
The converter template base class needs to be exported explicitly for the string specialization.
refs #1285
Merge branch 'bug-1285'
Backport: Fix further compilation errors on windows.
The converter template base class needs to be exported explicitly for the string specialization.
fixes #1285
History
#1 Updated by J. Wienke over 11 years ago
https://ci.cor-lab.org/job/rsb-cpp-trunk-windows-merge-simulator/VS_VERSION=100,label=windows/9/console
Michael:
- Do you see a difference in the source code I added in ProtocolBufferConverterTest.cpp to you own source code?
- Can you provide us the whole file that causes the compilation error?
- Is rsb linked statically or dynamically against your own project.
- What are you building? An executable or a library (static/shared?)?
#2 Updated by M. Zeunert over 11 years ago
- File DataReader.h added
- File ResultPublisher.h added
- File ResultPublisher.cpp added
- File ChessBoardFinder.cpp added
- File DataReader.cpp added
1. The main difference is that we include/use RSB in multiple files. If I register the converter in the main, it seems to work (recevieving not tested).
2. chessboardfinder.cpp (l. 59 -61 working code) resultpublisher.cpp (l. 23ff not working code)
datareader.cpp/h other class that uses rsb
3. I think its linked dynamically (not sure)
4. executable
#3 Updated by J. Wienke over 11 years ago
@Michael: Thanks for the information. Is ChessBoardFinder.cpp built in the same executable as the main method where it works or is it built in a (static/dynamic) library which you in turn link to your main code?
#4 Updated by M. Zeunert over 11 years ago
The chessboardfinder.cpp contains the main. When i put it in the Resultpublisher.cpp which is included in the chessboardfinder.cpp it produces this linking errors.
#5 Updated by J. Wienke over 11 years ago
Ok, thanks for the info. I was able to reproduce the problem:
https://ci.cor-lab.org/job/rsb-cpp-trunk-windows-merge-simulator/VS_VERSION=100,label=windows/10/console
I will try to find a solution.
#6 Updated by J. Wienke over 11 years ago
Great, this seems to be a harsh missconception of the MSVC C++ compiler:
http://www.codesynthesis.com/~boris/blog/2010/01/18/dll-export-cxx-templates/
#7 Updated by J. Wienke over 11 years ago
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100
Applied in changeset rsb-cpp|commit:cac97a942106cb72aba67fe996a83836b8941a64.
#8 Updated by J. Wienke over 11 years ago
Michael, should be working now again. Please reopen this if it still does not work.
#9 Updated by V. Losing over 11 years ago
after the update I'm getting a compiler error, when I try to compile our project.
:\test\environment_deb\include\rsb\converter\protocolbufferconverter.h(39): error C2961: 'rsb::converter::Converter<WireType>' : inconsistent explicit instantiations, a previous explicit instantiation did not specify '__declspec(dllimport)' 1> with 1> [ 1> WireType=std::string 1> ]
#10 Updated by J. Wienke over 11 years ago
- Status changed from Resolved to In Progress
- % Done changed from 100 to 60
sigh In which file is this compilation error?
#11 Updated by V. Losing over 11 years ago
rsb\converter\protocolbufferconverter.h(39)
it points on this code peace
#if defined(RSB_IMPORT_TEMPLATES)
template class __declspec(dllimport) rsb::converter::Converter<std::string>;
#endif
#12 Updated by J. Wienke over 11 years ago
But the error appears when you are compiling your own project? So in which file of your own project is this error generated?
#13 Updated by V. Losing over 11 years ago
- File ChessConverter.h added
- File ChessConverter.cpp added
its generated in any of our own converter i've added one as an example.
#14 Updated by J. Wienke over 11 years ago
Can you please try whether the git branch bug-1285 fixes your problem? I have added a completely new converter to the unit tests so that it is compiled like in any other client application. With this it builds on the CI server.
#15 Updated by V. Losing over 11 years ago
It seems that the branch bug-1285 is based on RSB 0.8. We use RSB 0.7, and rsc 0.7. Could you provide a fix-branch for 0.7?
#16 Updated by J. Wienke over 11 years ago
- File 0001-Fix-compilation-on-windows-again.patch added
Oh right. Attached is a patch file based on 0.7.
#17 Updated by V. Losing over 11 years ago
It compiles now, thanks.
#18 Updated by J. Wienke over 11 years ago
- Status changed from In Progress to Resolved
- % Done changed from 60 to 100
Applied in changeset rsb-cpp|commit:c81524f3ae842b30a416c83b08f62b29135a5272.