Skip to content

Conversation

@xezon
Copy link

@xezon xezon commented Jan 9, 2026

This change moves all CppMacros.h includes into precompiled headers.

This way CppMacros.h is made available everywhere with corei_always, gi_always or zi_always.

@xezon xezon added Build Anything related to building, compiling Refactor Edits the code with insignificant behavior changes, is never user facing labels Jan 9, 2026
@xezon
Copy link
Author

xezon commented Jan 9, 2026

Unfortunately Debug particleeditors will suddenly fail to compile for no apparent reason. Chat points to libci.lib but I was not able to resolve it by removing all suppressions (/NODEFAULTLIB:libci.lib) for it. Perhaps someone has more luck figuring out what the problem really is.

3>mfcs140d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRTD.lib(dll_dllmain_stub.obj)
1>mfcs140d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRTD.lib(dll_dllmain_stub.obj)
1>   Creating library D:/Projects/TheSuperHackers/GeneralsGameCode/build/win32/Generals/Code/Tools/ParticleEditor/Debug/ParticleEditor.lib and object D:/Projects/TheSuperHackers/GeneralsGameCode/build/win32/Generals/Code/Tools/ParticleEditor/Debug/ParticleEditor.exp
3>   Creating library D:/Projects/TheSuperHackers/GeneralsGameCode/build/win32/GeneralsMD/Code/Tools/ParticleEditor/Debug/ParticleEditor.lib and object D:/Projects/TheSuperHackers/GeneralsGameCode/build/win32/GeneralsMD/Code/Tools/ParticleEditor/Debug/ParticleEditor.exp
3>D:\Projects\TheSuperHackers\GeneralsGameCode\build\win32\GeneralsMD\Debug\ParticleEditor.dll : fatal error LNK1169: one or more multiply defined symbols found
1>D:\Projects\TheSuperHackers\GeneralsGameCode\build\win32\Generals\Debug\ParticleEditor.dll : fatal error LNK1169: one or more multiply defined symbols found

if (pobject) { \
delete [] pobject; \
pobject = NULL; \
} \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This magically failed to compile for no reason so I touched this and then it was fine.

D:\Projects\TheSuperHackers\GeneralsGameCode\Core\Tools\WW3D\max2w3d\util.h(113) : fatal error C1004: unexpected end of file found

Code is very strong here...

@sebyx07
Copy link

sebyx07 commented Jan 9, 2026

Analysis of the MFC DLL Linker Error

The _DllMain@12 already defined error occurs because of a dependency chain change:

Root Cause

Before this PR:

  • gi_alwayscore_utility + corei_libraries_include (both INTERFACE-only, no object code)

After this PR:

  • gi_alwayscorei_alwaysresources (STATIC library with gitinfo.cpp)

The resources static library contains compiled object code. When linked into an MFC DLL (_AFXDLL), the CRT's dll_dllmain_stub.obj gets pulled in before MFC's dllmodul.obj can provide its DllMain, causing the multiply-defined symbol error.

Suggested Fixes

Option 1: Exclude CRT DllMain stub for MFC tools

if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows")
    target_link_options(g_particleeditor PRIVATE 
        /NODEFAULTLIB:libci.lib 
        /NODEFAULTLIB:libc.lib
    )
    # Force link order: remove MSVCRTD then re-add it after MFC
    set_target_properties(g_particleeditor PROPERTIES 
        LINK_FLAGS "/NODEFAULTLIB:MSVCRTD.lib /DEFAULTLIB:MSVCRTD.lib")
endif()

Option 2: Create a lite version without resources (cleaner)

# In Core/CMakeLists.txt
add_library(corei_always_lite INTERFACE)
target_link_libraries(corei_always_lite INTERFACE
    core_utility
    corei_libraries_include
)
target_precompile_headers(corei_always_lite INTERFACE [["Utility/CppMacros.h"]])

Then have gi_always/zi_always use corei_always_lite, and only link resources to main game executables that actually need git info.

Option 3: Don't link gi_always into ParticleEditor

Keep ParticleEditor linking individual components it needs, add CppMacros.h to its own PCH separately.


The core issue is that MFC DLLs and static libraries with CRT dependencies don't mix well due to DllMain conflicts. Option 2 seems cleanest since it preserves your goal of making CppMacros.h available everywhere while avoiding the MFC conflict.

@xezon
Copy link
Author

xezon commented Jan 10, 2026

I checked if eliminating resources from linking would solve it but it does not. To do it, I reverted the _always lib changes and moved the CppMacros.h as precomp header to core_utility, where it is a better fit anyway.

Not pushed to this branch.

Skyaero42
Skyaero42 previously approved these changes Jan 10, 2026
@Skyaero42 Skyaero42 dismissed their stale review January 10, 2026 17:59

oops, just saw it was a draft and didn't compile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build Anything related to building, compiling Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants