V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  datadump  ›  全部回复第 27 页 / 共 50 页
回复总数  982
1 ... 23  24  25  26  27  28  29  30  31  32 ... 50  
2023 年 7 月 17 日
回复了 datadump 创建的主题 C++ c++ cmake 动态库的 std::string 为空,求指点(maocs-12.6)
2023 年 7 月 17 日
回复了 datadump 创建的主题 C++ c++ cmake 动态库的 std::string 为空,求指点(maocs-12.6)
@Shatyuka windows 的 DllMain.DLL_PROCESS_ATTACH 执行的比较晚,所以不会有这个问题,对吧
2023 年 7 月 17 日
回复了 datadump 创建的主题 C++ c++ cmake 动态库的 std::string 为空,求指点(maocs-12.6)
@Shatyuka 正解。谢谢
2023 年 7 月 17 日
回复了 datadump 创建的主题 C++ c++ cmake 动态库的 std::string 为空,求指点(maocs-12.6)
@chingyat 嗯。这个是没问题的。但是 g_test 不是固定值(会从文本读取)。runtime 执行一堆 constructor 的顺序问题。
2023 年 7 月 17 日
回复了 datadump 创建的主题 C++ c++ cmake 动态库的 std::string 为空,求指点(maocs-12.6)
这个不是编译器 bug ,是未指定行为
2023 年 7 月 17 日
回复了 datadump 创建的主题 C++ c++ cmake 动态库的 std::string 为空,求指点(maocs-12.6)
```
搞定了,把:
std::string g_test1;
std::string g_test2;
改成:
__attribute__((init_priority(101))) std::string g_test1;
__attribute__((init_priority(101))) std::string g_test2;

参考:
https://stackoverflow.com/questions/43941159/global-static-variables-initialization-issue-with-attribute-constructor-i
```
2023 年 7 月 17 日
回复了 datadump 创建的主题 C++ c++ cmake 动态库的 std::string 为空,求指点(maocs-12.6)
猜测的原因:__attribute__((constructor))时,c++ runtime 还未初始化,std::string 的一些操作可能不稳定。

测试:
```
std::string g_test1;
std::string g_test2;

__attribute__((constructor))
static void init() {
g_test1 = "hello test1";
printf("init: %s\n", g_test1.c_str());
}

void hello_func1(void) {
g_test2 = "hello test2";
printf("Hello World: %s, %s\n", g_test1.c_str(), g_test2.c_str());

return;
}

void hello_func2(void) {
printf("Hello World: %s, %s\n", g_test1.c_str(), g_test2.c_str());

return;
}
```

在 hello_func2 里面,g_test1 无法打印,g_test2 正常。

不知道这个思路是否正确,求大神指点
2023 年 7 月 14 日
回复了 BigBurNing 创建的主题 程序员 618 没赶上,现在想装机了,伙伴们给点建议吧
不缺那一百块的话,13600KF -> 13600K
2023 年 7 月 14 日
回复了 XSDo 创建的主题 程序员 三年网课,产出了一大批有证,能力一般的毕业生?
你这 hr 的 kpi 不给满分委屈了,直接写邮件,让老板给他加工资
2023 年 7 月 14 日
回复了 aguaiabcdef 创建的主题 程序员 想装个台式机,希望各位给点意见
内存太小了。我 10700 黑苹果都配了 64g
厉害了
2023 年 7 月 13 日
回复了 random1221 创建的主题 问与答 Chrome 如何禁止在新建 tab 时显示书签或历史记录?
上面的软件全试了一遍,tabby cat 比较好用
2023 年 7 月 10 日
回复了 v2ek 创建的主题 程序员 成都 3 年多 Vuer 前端求坑位~
感觉不错。只是简历太长看的累。18-25k 没问题
2023 年 7 月 10 日
回复了 liulei281 创建的主题 程序员 销售和开发的项目提成比例 8:1:1,这合理吗?
楼主得说下什么项目,特定场景还是终端用户。如果对接的资源稀缺难搞,别说占 8 ,占 10 都合理
要怎么平常心面对互联网上一茬又一茬更年轻更优秀的年轻人呢?
改成:
要怎么不学习不进步面对互联网上一茬又一茬更年轻更优秀的年轻人呢?
@RiESA 就是太麻烦啊。每星期节省 5 分钟撸代码它不香吗
界面做的不错
2023 年 7 月 6 日
回复了 v2exosawa 创建的主题 优惠信息 腾讯云服务器活动, 3 年 388, 2+2+4
@HL8 一台自用。没有多的
时间多:obsidian 是唯一选择
时间少:notion
2023 年 7 月 3 日
回复了 datadump 创建的主题 git 请教一个 git 指令(根据提交次数找到 commit id)
@retanoj good
1 ... 23  24  25  26  27  28  29  30  31  32 ... 50  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   987 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 30ms · UTC 22:37 · PVG 06:37 · LAX 15:37 · JFK 18:37
♥ Do have faith in what you're doing.