Hello,

In one of our projects we are using managed c++ together with Qt. After porting the code to Qt5 the following linker error occurs. This happens in every combination VS2008/2010 and win32/x64.

1>file2.obj : error LNK2005: "public: __cdecl `public: __cdecl QList<class QString>::QList<class QString>(class QList<class QString> const &)'::`5'::Cleanup::Cleanup(struct QListData::Data *)" (??0Cleanup@?4???0?$QList@VQString@@@@QEAA@AEBV1@@Z@QEAA@PEAUData@QListData@@@Z) already defined in file1.obj

The error is located in <QtCore/QList>.

The "Cleanup" struct is defined, declared and instantiated within the templated constructor of the class QList. If it is used in 2 independent .cpp files with the same template parameter than it should be created in both objects. But the linker can see that they are identical. When the compiler was called with the /clr flag this results in the linker error afterwards.

I tracked this down to a very simple example which is attached.

I am not sure if this is a bug from the compiler, a limitation of clr or if the Qt code itself is not valid. To me the code looks correct and I don't know of a limitation of CLR in that case.

Any ideas?

Best regards,
Franz




#include <QtCore/QStringList>

int main()
{
        return 0;
}
#include <QtCore/QStringList>


cmake_minimum_required(VERSION 2.8.10)
project(CLRLinkErrorDemo)
find_package(Qt5Core REQUIRED)

include_directories(${Qt5Core_INCLUDE_DIRS})
add_executable(CLRLinkErrorDemo file1.cpp file2.cpp)
target_link_libraries(CLRLinkErrorDemo ${Qt5Core_LIBRARIES})

# activate CLR and deactivate all incompatible switches
if(CMAKE_CXX_FLAGS_DEBUG MATCHES "/RTC1")
   string(REPLACE "/RTC1" " " CMAKE_CXX_FLAGS_DEBUG 
"${CMAKE_CXX_FLAGS_DEBUG}")
   message(STATUS ${PROJECT_NAME}  " CMAKE_CXX_FLAGS_DEBUG removing /RTC1")
endif()

if(CMAKE_CXX_FLAGS MATCHES "/EHsc")
   string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
   message(STATUS ${PROJECT_NAME}  " CMAKE_CXX_FLAGS removing /EHsc")
endif()
SET_TARGET_PROPERTIES(CLRLinkErrorDemo PROPERTIES COMPILE_FLAGS "/clr")  
set_property(TARGET CLRLinkErrorDemo PROPERTY VS_GLOBAL_KEYWORD "ManagedCProj")


_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to