1. 程式人生 > >c/c++ bug錦集(一)

c/c++ bug錦集(一)

一、錯誤資訊
warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]
  printf("time %u:%u\n",tv.tv_sec,tv.tv_usec);warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘__suseconds_t’ [-Wformat=]
       開始的時候沒有注意到錯誤資訊最後的[-Wformat=]提醒,一直以為是型別匹配錯了,把%u改成了%llu仍舊是不行。最後才注意到提醒。
然後在Ubuntu官網找到了原因:

NOTE: In Ubuntu 8.10 and later versions this option is enabled by default for C, C++, ObjC, ObjC++.  To disable, use -Wformat=0.
然後在編譯的時候改成了:gcc test.c -Wformat=0 就沒問題了。Wformat這個配置在Centos下預設是關閉的,所以一直沒報錯,如果編譯的時候開啟,也會提示一樣的錯誤。


看來不同的平臺,很多預設的設定還是不一樣的。


Ubuntu官網的解釋:http://manpages.ubuntu.com/manpages/oneiric/en/man1/gcc.1.html
二、錯誤:

dso.o:在函式‘dso_load(char const*, char const*)’中:
dso.cpp:(.text+0x3c):對‘dlopen’未定義的引用
dso.cpp:(.text+0x4c):對‘dlsym’未定義的引用
dso.cpp:(.text+0xb5):對‘dlerror’未定義的引用

dso.cpp:(.text+0x13e):對‘dlclose’未定義的引用

編譯c ,如果引用了.o檔案,多個.o檔案吧,不能直接執行gcc demo.c -o demo,需要分步驟進行

以下是解決方案:
(在多個.o的地方執行   gcc demo1.o demo2.0 -o demo)
https://jingyan.baidu.com/article/d5a880eb8fa71d13f147cc88.html
http://blog.csdn.net/qq_29350001/article/details/53339861

我是小白,在開發科大訊飛語音喚醒的時候學習到的