Library
- static libraries
- shared libraries
- dynamically loaded libraries
- What is the effect of extern "C" in C++?
- One Definition Rule
- C++ Compiler Explained: What is the Compiler and How Do You Use it?
-
C++ Compiler Operation
The C++ compiler system
The preprocessor: #define and #include
错误 corrupted size vs. prev_size
运行时报告如下错误,并产生 core 文件:
*** Error in `../lib/svd_bpack_gen': corrupted size vs. prev_size: 0x0000000000a58250 ***
进行 gdb 调试:gdb ../lib/svd_bpack_gen core.9954
,报告:
Missing separate debuginfos, use: debuginfo-install glibc-2.17-322.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64 libstdc++-4.8.5-44.el7.x86_64 zlib-1.2.7-19.el7_9.x86_64
进行:sudo debuginfo-install glibc-2.17-322.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64 libstdc++-4.8.5-44.el7.x86_64 zlib-1.2.7-19.el7_9.x86_64
安装。
CMake
-
CMAKE_DL_LIBS:类同
-ldl
- execute_process:执行命令。
-
add_subdirectory:
add_subdirectory(源文件目录 输出文件目录)
- Output Artifacts:要将编译结果文件存放何处,就看这里,比如:可执行文件,.a文件,.so文件等。
- find_library:
- 下载 源码,以3.20.6为例。
- 执行
./bootstrap && make && sudo make install
进行安装。
安装后,执行 cmake,出现如下问题:
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/local/bin
Segmentation fault
Do hash -r to clear the cache, then do cmake --version. 打印出 3.20.6,即告恢复正常。
-
cmake -L ..
For a list of all configure options, runcmake -L ..
C++ 的静态成员函数
-
Why can static member function definitions not have the keyword 'static'?
静态成员函数在声明时加 static 关键字,但在定义时不能加。上面这篇贴子说的很清楚。
编译选项
- Static and Dynamic ‘C’ Libraries:对编译命令 gcc, ar 有解释。
- position-independent code (PIC)
-
-DCMAKE_BUILD_TYPE=Debug
:编译 debug 版本。 - What is the idiomatic way in CMAKE to add the -fPIC compiler option?
- Difference between shared objects (.so), static libraries (.a), and DLL's (.so)?:共享对象、静态库、动态库?
- #pragma pack effect:It forces a particular alignment/packing of a struct, but like all #pragma directives they are implementation defined. 结构对齐的编译选项。
make
-
make &> results.txt
可以把 make 编译结果输出到 results.txt 中。 -
patsubst
: 文本替换。 -
notdir
:类似于 basename,文件名函数。 - 一个 Makefile 文件示例
include ./Makefile.in
DEST_PATH = /opt/bpack_gen/libexec
PWD := $(shell pwd)
BASENAME := $(shell basename ${PWD})
DATE := $(shell date +%Y%m%d)
$(info $(BASENAME) )
PROG = libbase_${BASENAME}.so.$(DATE)
LNPROG = libbase_${BASENAME}.so
LIBPROG = libbase_${BASENAME}.a
网友评论