Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trouble compiling files with identical filenames
QtWS25 Last Chance

Trouble compiling files with identical filenames

Scheduled Pinned Locked Moved Solved General and Desktop
qtcreatorqmake
11 Posts 5 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jsmolka
    wrote on last edited by aha_1980
    #1

    Hey there,

    I am currently working on a project which contains some duplicate class names. To prevent them from clashing I am using namespaces. Then I can use those classes the following way

    #include "core/audio.hpp"  // Audio class
    #include "core/database/dbaudio.hpp"  // db::Audio class
    

    Now I really dislike the fact of needing the extra db -prefix for the database class. I tried changing the class name to just audio.hpp but that raised an error while compiling with MSVC.
    Then I googled around and found the qmake config values object_parallel_to_source (and its older brother object_with_source). When compiling the project using CONFIG += object_parallel_to_source I get the compiler error LNK1181: File "release/src/main.obj" cannot be opened..

    Is there any way to fix that and use multiple files with the same name inside my Qt project? Does it perhaps have something to do with the fact, that I am compiling into a bin dir inside my repository?

    aha_1980A kshegunovK 2 Replies Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Putting aside the fact that using same file names for different files (and classes!) is very confusing - and thus makes code maintenance harder.

      Do you use proper header guards in your header files? Ifdefs or pragma or both?

      (Z(:^

      1 Reply Last reply
      2
      • J Offline
        J Offline
        jsmolka
        wrote on last edited by
        #3

        Yes, I am using proper include guards. What would a good way of naming those classes? I am using Audio mostly as a data class and db::Audio as an "interface" for the database. I used to call it DbAudio but then I had lots of classes prefixed Db and decided to put them all into a namespace.
        The current main problem is keeping the class names as easy as possible without name clashing :(

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          If it is an interface, it can be called AudioInterface. Or as some people do: IAudio.

          If it holds data, it could be AudioData, or in more webby style: AudioTransferObject.

          OK if you are using header guards, then indeed the issue is likely to come from putting the object files in single directory. Two possible workarounds:

          • move one of the headers to a separate .pri file - not sure if that causes build layout to change, but it is the easiest to check
          • separate part of your project into a subproject (qmake's TEMPLATE = subdirs), possibly as a library, and then include with your main app

          (Z(:^

          1 Reply Last reply
          2
          • J Offline
            J Offline
            jsmolka
            wrote on last edited by jsmolka
            #5

            But shouldn't object_parallel_to_source work right out of the box? From what I understand it's supposed to mimic the project directory structure when compiling and should thereby eliminate duplicate .obj-files in the same directory. The problem is the almost instant error mentioned in the first post.

            sierdzioS 1 Reply Last reply
            0
            • J jsmolka

              But shouldn't object_parallel_to_source work right out of the box? From what I understand it's supposed to mimic the project directory structure when compiling and should thereby eliminate duplicate .obj-files in the same directory. The problem is the almost instant error mentioned in the first post.

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              @jsmolka said in Trouble compiling files with indentical filenames:

              But shouldn't object_parallel_to_source work right out of the box?

              No idea - if this option exists, it is not documented in qmake manual.

              (Z(:^

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                What version of Qt are you using to build your project ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  What version of Qt are you using to build your project ?

                  J Offline
                  J Offline
                  jsmolka
                  wrote on last edited by jsmolka
                  #8

                  @SGaist I am using the current version (5.11.2) and the up-to-date QtCreator. I am building my project with object_parallel_to_source enabled and it only works when I disable shadow build. I would love to use the feature in combination with shadow build.

                  1 Reply Last reply
                  0
                  • J jsmolka

                    Hey there,

                    I am currently working on a project which contains some duplicate class names. To prevent them from clashing I am using namespaces. Then I can use those classes the following way

                    #include "core/audio.hpp"  // Audio class
                    #include "core/database/dbaudio.hpp"  // db::Audio class
                    

                    Now I really dislike the fact of needing the extra db -prefix for the database class. I tried changing the class name to just audio.hpp but that raised an error while compiling with MSVC.
                    Then I googled around and found the qmake config values object_parallel_to_source (and its older brother object_with_source). When compiling the project using CONFIG += object_parallel_to_source I get the compiler error LNK1181: File "release/src/main.obj" cannot be opened..

                    Is there any way to fix that and use multiple files with the same name inside my Qt project? Does it perhaps have something to do with the fact, that I am compiling into a bin dir inside my repository?

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @jsmolka

                    (Personal opinion): Identical filenames in a project lead to problems sooner or later.

                    Instead of working around the problem, you should just avoid these different classes with same name. @sierdzio already gave examples how structure things better.

                    Even if you get it running now, it may break anytime, leading to addional time to fix these things. Better invest that time into development.

                    Regards

                    Qt has to stay free or it will die.

                    J 1 Reply Last reply
                    1
                    • aha_1980A aha_1980

                      @jsmolka

                      (Personal opinion): Identical filenames in a project lead to problems sooner or later.

                      Instead of working around the problem, you should just avoid these different classes with same name. @sierdzio already gave examples how structure things better.

                      Even if you get it running now, it may break anytime, leading to addional time to fix these things. Better invest that time into development.

                      Regards

                      J Offline
                      J Offline
                      jsmolka
                      wrote on last edited by
                      #10

                      @aha_1980 You probably right. I am still learning C++ and I am currently trying to figure out the best way to organize my source files. Currently project structure looks something like this:

                      src/
                      ├── namespace1/
                      │ ├── namespace1_base.cpp
                      │ ├── namespace1_derived1.cpp
                      │ └── namespace1_derived2.cpp
                      ├── namespace2/
                      │ ├── namespace2_base.cpp
                      │ ├── namespace2_derived3.cpp
                      │ └── namespace2_derived4.cpp
                      ├── other.cpp
                      └── files.cpp

                      I usually use a Base class which implements functionality the classes inside the namespace need. It just seems odd not to call the source file base.cpp because I can't use duplicate files names.

                      1 Reply Last reply
                      0
                      • J jsmolka

                        Hey there,

                        I am currently working on a project which contains some duplicate class names. To prevent them from clashing I am using namespaces. Then I can use those classes the following way

                        #include "core/audio.hpp"  // Audio class
                        #include "core/database/dbaudio.hpp"  // db::Audio class
                        

                        Now I really dislike the fact of needing the extra db -prefix for the database class. I tried changing the class name to just audio.hpp but that raised an error while compiling with MSVC.
                        Then I googled around and found the qmake config values object_parallel_to_source (and its older brother object_with_source). When compiling the project using CONFIG += object_parallel_to_source I get the compiler error LNK1181: File "release/src/main.obj" cannot be opened..

                        Is there any way to fix that and use multiple files with the same name inside my Qt project? Does it perhaps have something to do with the fact, that I am compiling into a bin dir inside my repository?

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #11

                        @jsmolka said in Trouble compiling files with identical filenames:

                        Is there any way to fix that and use multiple files with the same name inside my Qt project? Does it perhaps have something to do with the fact, that I am compiling into a bin dir inside my repository?

                        Not with shadow building, no. When you generate a bunch of object files in the same directory, the object is named after the source file. So the identically named source's object file will overwrite the previous one (in order of building); it may even happen only partially if you're building on multiple cores.
                        It's a known pitfall and you should name your files better as people have already suggested.

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        4

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved