Bug #1285

converter template class breaks linking on windows

Added by J. Wienke almost 9 years ago. Updated almost 9 years ago.

Status:ResolvedStart date:12/07/2012
Priority:NormalDue 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

DataReader.h Magnifier (1.73 KB) M. Zeunert, 12/08/2012 12:04 PM

ResultPublisher.h Magnifier (1.31 KB) M. Zeunert, 12/08/2012 12:04 PM

ResultPublisher.cpp Magnifier (2.09 KB) M. Zeunert, 12/08/2012 12:04 PM

ChessBoardFinder.cpp Magnifier (18.4 KB) M. Zeunert, 12/08/2012 12:04 PM

DataReader.cpp Magnifier (2.91 KB) M. Zeunert, 12/08/2012 12:04 PM

ChessConverter.h Magnifier (721 Bytes) V. Losing, 12/18/2012 11:29 AM

ChessConverter.cpp Magnifier (2.46 KB) V. Losing, 12/18/2012 11:29 AM

0001-Fix-compilation-on-windows-again.patch Magnifier (8.16 KB) J. Wienke, 12/18/2012 02:52 PM

Associated revisions

Revision 091c8d0e
Added by J. Wienke almost 9 years ago

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

Revision cac97a94
Added by J. Wienke almost 9 years ago

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

Revision 9ead44d4
Added by J. Wienke almost 9 years ago

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'

Revision c81524f3
Added by J. Wienke almost 9 years ago

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 almost 9 years ago

I tried to reproduce this with commit rsb-cpp|0e96d5e4239bb2dee80dcaa4ee7b3d0fe70a1216. However, this built perfectly on our continuous integration server:
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 almost 9 years ago

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 almost 9 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 almost 9 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 almost 9 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 almost 9 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 almost 9 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 almost 9 years ago

Michael, should be working now again. Please reopen this if it still does not work.

#9 Updated by V. Losing almost 9 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 almost 9 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 almost 9 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 almost 9 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 almost 9 years ago

its generated in any of our own converter i've added one as an example.

#14 Updated by J. Wienke almost 9 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 almost 9 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 almost 9 years ago

Oh right. Attached is a patch file based on 0.7.

#17 Updated by V. Losing almost 9 years ago

It compiles now, thanks.

#18 Updated by J. Wienke almost 9 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 60 to 100

Applied in changeset rsb-cpp|commit:c81524f3ae842b30a416c83b08f62b29135a5272.

Also available in: Atom PDF