<div dir="ltr">Hi,<div><br></div><div>I'm porting a rather large project/library from Linux to Windows and was looking for an automatic symbol export solution, and found the WINDOWS_EXPORT_ALL_SYMBOLS to be excellent. It works almost nicely, however there is a problem with the .def file it creates.</div><div>Upon linking I get errors like this:</div><div><br></div><div><div>exports.def : warning LNK4022: cannot find unique match for symbol '_CT??_R0?AU?$error_info_injector'</div><div>exports.def : warning LNK4002: _CT??_R0?AU?$error_info_injector@Ubad_day_of_month@gregorian@boost@@@exception_detail@boost@@@864 defined in ...</div><div><div>exports.def : warning LNK4002: _CT??_R0?AU?$error_info_injector@Ubad_month@gregorian@boost@@@exception_detail@boost@@@864 defined in ...</div></div></div><div>...</div><div>exports.def : error LNK2001: unresolved external symbol _CT??_R0?AU?$error_info_injector<br></div><div>...</div><div><br></div><div>So first several warnings then finally errors. MSDN also sais this: <a href="https://msdn.microsoft.com/en-us/library/3802xyyy.aspx">https://msdn.microsoft.com/en-us/library/3802xyyy.aspx</a></div><div><br></div><div>Apparently, the .def file has lines like this which cause the problem:</div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>_CT??_R0?AU?$error_info_injector <span class="gmail-Apple-tab-span" style="white-space:pre">     </span> DATA</div></div><div>...</div><div><br></div><div>If I manually delete the lines referenced in the above errors from the generated .def file, the DLL builds fine.</div><div><br></div><div>The project uses a lot of third party libraries, boost is one of them. The symbols that cause the problem are probably not even need to be exported.</div><div><br></div><div>So my question is, how can I solve this? My first idea was to create a sort of "blacklist" and write a script that "heals" the .def file by removing the problematic lines. However it is not possible to do, as the WINDOWS_EXPORT_ALL_SYMBOLS step is added internally by CMake as a final PRE_LINK step, and I found no way add a command between the .def file generation and the actual linking.</div><div><br></div><div>I thought about adding a custom command which would emulate the behaviour of WINDOWS_EXPORT_ALL_SYMBOLS, however I cannot easily get the object file list in a convenient file as WINDOWS_EXPORT_ALL_SYMBOLS does.</div><div><br></div><div>So I'm stuck at this point, any help would me much appreciated.</div><div><br></div><div>Additional BUG:</div><div>I probably found a bug as well in the process. If I enable WINDOWS_EXPORT_ALL_SYMBOLS but I also add a custom PRE_LINK step with add_custom_command() like this:</div><div><br></div><div>add_custom_command(TARGET zp_core PRE_LINK COMMAND echo Hello)<br></div><div><br></div><div>then I get the following output:</div><div><br></div><div>...</div><div><div>Hello</div><div>Couldn't open file 'lib\core\CMakeFiles\zp_core.dir\background_thread.cpp.obj' with CreateFile()</div></div><div><br></div><div>It seems when I add the custom command, then CMake first changes the directory like so (using blabla as example):</div><div><br></div><div>cmd.exe /C "cmd.exe /C "cd /D C:\blablabla && echo Hello && "C:\Program Files\CMake\bin\cmake.exe" -E __create_def ... <br></div><div><br></div><div>while if there is no custom command present, it looks like this:</div><div><br></div><div>cmd.exe /C "cmd.exe /C ""C:\Program Files\CMake\bin\cmake.exe" -E __create_def <br></div><div><br></div><div>I believe in the custom command case the "__create_def" step is executed in the wrong working directory and CMake fails to open the object file listed in the exports.def.objs list.</div><div><br></div><div>Thanks in advance,</div><div>Balázs</div><div><br></div></div>