View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000288 | file | General | public | 2021-09-13 07:18 | 2021-09-20 17:46 |
Reporter | Cirn09 | Assigned To | christos | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Fixed in Version | 5.41 | ||||
Summary | 0000288: Naming conflict when compiling libmagic as Windows static library | ||||
Description | hello, I want build `libmagic` as static library for Windows. But `libmagic` define the `DllMain` in `magic.c`: ``` /* Placate GCC by offering a sacrificial previous prototype */ BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID); BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved __attribute__((__unused__))) { if (fdwReason == DLL_PROCESS_ATTACH) _w32_dll_instance = hinstDLL; return 1; } ``` This causes naming conflicts when linking libmagic to a dynamic library: > `libmagic.lib(magic.obj) : error LNK2005: DllMain already defined in dllmain.obj` `DllMain` is only used to initialize `_w32_dll_instance`. In fact, for static libraries, `_w32_dll_instance` is not needed. `_w32_dll_instance` only used in `get_default_magic` ``` private const char * get_default_magic(void) { ... /* Fourth, try to get magic file relative to exe location */ _w32_get_magic_relative_to(&hmagicpath, NULL); /* Fifth, try to get magic file relative to dll location */ _w32_get_magic_relative_to(&hmagicpath, _w32_dll_instance); /* Fifth, try to get magic file relative to dll location */ _w32_get_magic_relative_to(&hmagicpath, _w32_dll_instance); ... static void _w32_get_magic_relative_to(char **hmagicpath, HINSTANCE module) { ... if (!GetModuleFileNameA(module, dllpath, MAX_PATH)) ... ``` > Parameters > hModule > A handle to the loaded module whose path is being requested. If this parameter is **NULL**, > GetModuleFileName retrieves the path of the executable file of the current process. > https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea I think to solve this problem need to add a new macro judgment, like: ``` #ifndef BUILD_AS_WINDOWS_STATIC_LIBARAY BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) ... #endif ``` | ||||
Tags | build | ||||
Date Modified | Username | Field | Change |
---|---|---|---|
2021-09-13 07:18 | Cirn09 | New Issue | |
2021-09-13 07:18 | Cirn09 | Tag Attached: build | |
2021-09-20 17:45 | christos | Assigned To | => christos |
2021-09-20 17:45 | christos | Status | new => assigned |
2021-09-20 17:46 | christos | Status | assigned => resolved |
2021-09-20 17:46 | christos | Resolution | open => fixed |
2021-09-20 17:46 | christos | Fixed in Version | => 5.41 |
2021-09-20 17:46 | christos | Note Added: 0003646 |