C++ global variable not initialized when linked through static libraries, but OK when compiled with source

后端 未结 2 1211
感情败类
感情败类 2020-12-13 14:21

I have created a system that automatically registers function objects (functors) into a map based on the constructor of an global instance.

In each cpp file that def

2条回答
  •  臣服心动
    2020-12-13 14:50

    I believe your object file from the library is not getting linked. Look how Microsoft handles the acrtused symbol (search case insensitive, I do not remember the case and there's no MSVC on this machine).

    Once you know how they handle acrtused, do the same thing with your global variable to force it to get linked.

    Will update if I find the answer.

    Here are a couple of possibilities to force things to link and initialize in a somewhat forced order.

    Look here for a GCC answer.

    Look here for MSVC10.

提交回复
热议问题