artem-ogre/CDT

.h and .hpp files with the same name

petrasvestartas opened this issue · 9 comments

Hi,

Maybe this is amateur question. But why in "\CDT\include" there are files with the same names e.g. CDT.h and CDT.hpp ?
Wont they be conflicting while linking?

I really have problem that I cannot solve for days.
If I #include <CDT.h> to precompiled headers it always produces the error below:

I download CDT with cmake in the build folder like this:

  #######################################################################
  # CDT
  ####################################################################### 
  ExternalProject_Add(cdt
      URL https://github.com/artem-ogre/CDT/archive/refs/tags/1.1.2.zip
      CMAKE_ARGS
        -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
        -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
        #-DCMAKE_INSTALL_PREFIX:PATH="${CMAKE_BINARY_DIR}/install"
      SOURCE_DIR   "${CMAKE_BINARY_DIR}/install/cdt"
        #INSTALL_DIR   "${CMAKE_INSTALL_PREFIX}/install"
      CONFIGURE_COMMAND "" #do not configure
      BUILD_COMMAND "" #do not buld
      INSTALL_COMMAND "" #installer for now is empty
  )

main.obj : error LNK2005: "class std::vector<unsigned short,class std::allocator<unsigned short> > __cdecl CDT::
CalculateTriangleDepths(unsigned int,class std::vector<struct CDT::Triangle,class std::allocator<struct CDT::Tri
angle> > const &,class std::unordered_set<struct CDT::Edge,struct std::hash<struct CDT::Edge>,struct std::equal_
to<struct CDT::Edge>,class std::allocator<struct CDT::Edge> > const &,class std::unordered_map<struct CDT::Edge,
unsigned short,struct std::hash<struct CDT::Edge>,struct std::equal_to<struct CDT::Edge>,class std::allocator<st
ruct std::pair<struct CDT::Edge const ,unsigned short> > > const &)" (?CalculateTriangleDepths@CDT@@YA?AV?$vecto
r@GV?$allocator@G@std@@@std@@IAEBV?$vector@UTriangle@CDT@@V?$allocator@UTriangle@CDT@@@std@@@3@AEBV?$unordered_s 
et@UEdge@CDT@@U?$hash@UEdge@CDT@@@std@@U?$equal_to@UEdge@CDT@@@4@V?$allocator@UEdge@CDT@@@4@@3@AEBV?$unordered_m 
ap@UEdge@CDT@@GU?$hash@UEdge@CDT@@@std@@U?$equal_to@UEdge@CDT@@@4@V?$allocator@U?$pair@$$CBUEdge@CDT@@G@std@@@4@ 
@3@@Z) already defined in cmake_pch.obj [C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\compas_wood\build_win\c 
ompas_wood.vcxproj]
C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\compas_wood\build_win\Release\compas_wood.exe : fatal error LNK1
169: one or more multiply defined symbols found [C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\compas_wood\bui 
ld_win\compas_wood.vcxproj]

Do you experience the same problem if you use the latest master?

Could you provide a minimal example that reproduces this problem? I could poke it when there's time.
I am not very familiar with ExternalProject_Add but I think this is something I would like to work :)

@artem-ogre

This is a very minimal example. I removed all my code to illustrate the most simple example.
I really spend full days from morning till evening to search for the problem, and it really boils down to "CDT.h" file in the precompiled header "stdafx.h".
If you cannot solve this issue with precompiled header, please show me an example within my code structure, how CDT can be CMake configured as a library and then included in the precompiled header.

Unzip then use these commands:
cdt_test.zip

  1. Go to folder that is downloaded
    cd ..\cdt_test
  2. Run Download first CDT and GLM libraries (GLM is used only to store xyz points)
    cmake --fresh -DGET_LIBS=ON -DBUILD_MY_PROJECTS=OFF -DCMAKE_BUILD_TYPE="Release" -G "Visual Studio 17 2022" -A x64 .. && cmake --build . --config Release
  3. Build the executable with precompiled header stdafx.
    cmake --fresh -DGET_LIBS=OFF -DBUILD_MY_PROJECTS=ON -DCMAKE_BUILD_TYPE="Release" -G "Visual Studio 17 2022" -A x64 .. && cmake --build . --config Release
  4. To Run the files type this, but this wont work until the step 3 is solved, it will work only if header "CDT.h" is included in the main.cpp not stdafx.h
    Release\cdt_test

main.obj : error LNK2005: "class std::vector<unsigned short,class std::allocator > __cdecl CDT::
CalculateTriangleDepths<...> already defined in cmake_pch.obj

I believe the issue is solved on master in 4fa94ab

Since this commit was made in 2021.
Why this does not work on the current version? I use ExternalProject_Add to download the latest release:
URL https://github.com/artem-ogre/CDT/archive/refs/tags/1.1.2.zip

Would you have time to check the CMakeLists and the code itself?

The commit was done after the last release :) The last release is old and master moved a long way since.

Works perfectly, by cloning the repo itself.
Thank you.
Would it be possible to add the current version to the release?

After two days of check all possible things, I finally feel that this is over:
thumb_compile-compile-error-error-compile-error-compile-error-cmon-alreadym-61753648

I've done a new release from the current master: https://github.com/artem-ogre/CDT/releases/tag/1.2.0
I still recommend avoiding releases and leaving on the main branch if latest and greatest is required.

Thank you very much;)