[Linux_C][2010-9-20]BAD_CAST

本文介绍libxml中API如何使用BAD_CAST进行类型转换,解决string literal只能隐式转换到const char*的问题。通过具体示例展示了BAD_CAST在xmlNewTextChild函数中的应用。

libxml的api使用 const unsigned char* 。
而string literal 只能隐式转换到 const char*。
所以libxml提供一个BAD_CAST用来作显示转换。

 

 

例:

xmlNewTextChild(root_node, NULL, BAD_CAST "Version", BAD_CAST read_buf);

 

强制类型装换, 用法类似于(int *)

 

CROSS_COMPILE := $(TOOLCHAIN_PREFIX) CC := $(CROSS_COMPILE)gcc$(TOOLCHAIN_SUFFIX) CXX := $(CROSS_COMPILE)g++ AR := $(CROSS_COMPILE)ar RANLIB := $(CROSS_COMPILE)ranlib STRIP := $(CROSS_COMPILE)strip BUILD_DIR ?= ../../build/sample/linux INLCUDE := -I$(GLOBAL_INC_DIR) -I./ -I./librtsp -I../../common CFLAG := $(GLOBAL_CFLAGS) $(PLAT_CFLAGS) CFLAG += $(INLCUDE) ifeq ($(GLOBAL_PLATFORM), T40_ISVP) CFLAG += -DPPS_MEDIA_T40 else ifeq ($(GLOBAL_PLATFORM), T40Z_ZERATUL) CFLAG += -DPPS_MEDIA_T40Z else ifeq ($(GLOBAL_PLATFORM), T23_ISVP_DUAL) CFLAG += -DPPS_MEDIA_T23_DUAL endif CFLAG += -ffunction-sections -fdata-sections CFLAG += -D__LINUX__ ifeq ($(CONFIG_PPS_MEDIA_FONT_RENDER), gbk) CFLAG += -DCONFIG_PPS_MEDIA_FONT_BITMAP_GBK endif CXXFLAGS := $(GLOBAL_CXXFLAGS) $(INLCUDE) $(PLAT_CXXFLAGS) LDFLAG := -L./librtsp -lrtsp -L./medialib -lppsmedia $(PLAT_LDFLAGS) LDFLAG += -Wl,--gc-sections LD_CXXFLAG := $(LDFLAG) SOURCE := $(filter-out sample_client.c, $(wildcard *.c)) DEPS := $(SOURCE:%.c=$(BUILD_DIR)/%.d) OBJECT := $(SOURCE:%.c=$(BUILD_DIR)/%.o) OBJ-DIRS := $(sort $(dir $(OBJECT))) LINK_WITH_CXX := no ifeq ($(WITH_CXX_LIBRARY), yes) LINK_WITH_CXX := yes endif ifneq ($(filter *.cpp,$(SOURCE)),) LINK_WITH_CXX := yes endif ifeq ($(WITH_CXX_SOURCES), yes) LINK_WITH_CXX := yes endif ifneq ($(MAKECMDGOALS),clean) _dummy := $(shell [ -d $(BUILD_DIR) ] || mkdir -p $(BUILD_DIR)) _dummy := $(foreach d,$(OBJ-DIRS), $(shell [ -d $(d) ] || mkdir -p $(d))) endif rtsplib: make -C librtsp sample: $(OBJECT) @echo "" @echo "[Sample is ready ... ]" rm -rf medialib mkdir -p medialib cp -r $(GLOBAL_BIN_DIR)/lib/* medialib ifeq ($(WITH_CXX_LIBRARY), yes) cd medialib && cp libppsmedia.a libppsmedia_cxx.a endif ifeq ($(LINK_WITH_CXX), yes) $(CXX) $(OBJECT) $(CXXFLAGS) $(LD_CXXFLAG) -o sample_media else $(CC) $(OBJECT) $(CFLAG) $(LDFLAG) -o sample_media endif $(CC) $(CFLAG) $(LDFLAG) -Wno-bad-function-cast sample_client.c -o media_client cp sample_media sample_media_unstripped $(STRIP) sample_media if [ -d "$(TFTPBOOT)" ]; then cp sample_media $(TFTPBOOT); fi if [ -d "$(TFTPBOOT)" ]; then cp media_client $(TFTPBOOT); fi if [ -e "librtsp/librtsp.a" ]; then rm librtsp/librtsp.a; fi all: rtsplib sample .PHONY: clean rtsplib sample clean: @-rm -f sample_media sample_media_unstripped media_client @-rm -rf medialib @make -C librtsp clean $(BUILD_DIR)/%.o:%.c $(CC) $(CFLAG) -c $< -o $@ -MMD ifneq ($(MAKECMDGOALS),clean) -include (DEPS) endif 上述代码为什么会显示./media_t23/lib/libppsmedia.a(barcode.o): In function `plat_barcode_image_process&#39;: /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:216: undefined reference to `IMP_ISP_Tuning_GetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:216: undefined reference to `IMP_ISP_Tuning_GetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:220: undefined reference to `IMP_ISP_Tuning_SetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:220: undefined reference to `IMP_ISP_Tuning_SetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:223: undefined reference to `IMP_ISP_Tuning_GetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:223: undefined reference to `IMP_ISP_Tuning_GetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:227: undefined reference to `IMP_ISP_Tuning_GetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:227: undefined reference to `IMP_ISP_Tuning_GetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:231: undefined reference to `IMP_ISP_Tuning_GetAE_IT_MAX&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:231: undefined reference to `IMP_ISP_Tuning_GetAE_IT_MAX&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:240: undefined reference to `IMP_ISP_Tuning_SetAe_IT_MAX&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:240: undefined reference to `IMP_ISP_Tuning_SetAe_IT_MAX&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:229: undefined reference to `IMP_ISP_Tuning_SetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:229: undefined reference to `IMP_ISP_Tuning_SetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:225: undefined reference to `IMP_ISP_Tuning_SetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:225: undefined reference to `IMP_ISP_Tuning_SetMaxAgain&#39; ./media_t23/lib/libppsmedia.a(barcode.o): In function `plat_barcode_isp_deinit&#39;: /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:159: undefined reference to `IMP_ISP_Tuning_GetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:159: undefined reference to `IMP_ISP_Tuning_GetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:161: undefined reference to `IMP_ISP_Tuning_SetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:161: undefined reference to `IMP_ISP_Tuning_SetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:162: undefined reference to `IMP_ISP_Tuning_SetAe_IT_MAX&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:162: undefined reference to `IMP_ISP_Tuning_SetAe_IT_MAX&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:163: undefined reference to `IMP_ISP_Tuning_SetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:163: undefined reference to `IMP_ISP_Tuning_SetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:164: undefined reference to `IMP_ISP_Tuning_SetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:164: undefined reference to `IMP_ISP_Tuning_SetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:172: undefined reference to `IMP_ISP_Tuning_GetModuleControl&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:172: undefined reference to `IMP_ISP_Tuning_GetModuleControl&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:175: undefined reference to `IMP_ISP_Tuning_SetModuleControl&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:175: undefined reference to `IMP_ISP_Tuning_SetModuleControl&#39; ./media_t23/lib/libppsmedia.a(barcode.o): In function `plat_barcode_isp_init&#39;: /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:83: undefined reference to `IMP_ISP_Tuning_GetISPRunningMode&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:83: undefined reference to `IMP_ISP_Tuning_GetISPRunningMode&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:83: undefined reference to `IMP_ISP_Tuning_GetISPRunningMode&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:83: undefined reference to `IMP_ISP_Tuning_GetISPRunningMode&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:113: undefined reference to `IMP_ISP_Tuning_GetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:113: undefined reference to `IMP_ISP_Tuning_GetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:116: undefined reference to `IMP_ISP_Tuning_SetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:116: undefined reference to `IMP_ISP_Tuning_SetAeMin&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:118: undefined reference to `IMP_ISP_Tuning_GetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:118: undefined reference to `IMP_ISP_Tuning_GetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:120: undefined reference to `IMP_ISP_Tuning_SetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:120: undefined reference to `IMP_ISP_Tuning_SetMaxAgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:122: undefined reference to `IMP_ISP_Tuning_GetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:122: undefined reference to `IMP_ISP_Tuning_GetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:124: undefined reference to `IMP_ISP_Tuning_SetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:124: undefined reference to `IMP_ISP_Tuning_SetMaxDgain&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:126: undefined reference to `IMP_ISP_Tuning_GetAE_IT_MAX&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:126: undefined reference to `IMP_ISP_Tuning_GetAE_IT_MAX&#39; /home/sx_xuzhihao/pps-media/plat/Ingenic/T2X_IPC/src/barcode.c:133: undefined reference to `IMP_ISP_Tuning_SetAe_IT_MAX&#39;我明明加载了这个头文件和静态库
08-02
在编译过程中遇到 `undefined reference to `IMP_ISP_Tuning_*&#39;` 的链接错误,通常表明链接器无法找到这些函数的实现。尽管已经包含了相关的头文件和静态库,但仍可能由于以下几个原因导致此错误: 1. **静态库未正确链接** 确保在链接命令中显式地指定了 `libppsmedia.a` 静态库,并且链接顺序正确。例如,在使用 `gcc` 或 `g++` 编译时,应将静态库放在源文件之后,例如: ```bash gcc main.o -L/path/to/lib -lppsmedia -o myapp ``` 如果库文件不在标准路径中,还需要使用 `-L` 参数指定库的路径。 2. **函数符号未在库中定义** 使用 `nm` 或 `objdump` 工具检查 `libppsmedia.a` 中是否确实包含 `IMP_ISP_Tuning_*` 相关的符号。例如: ```bash nm libppsmedia.a | grep IMP_ISP_Tuning_ ``` 如果没有找到这些符号,则可能是库版本不匹配或构建时未包含相关模块。 3. **编译器与库的 ABI 兼容性问题** 确保编译器版本、C++ 标准(如 `-std=c++11`)、架构(32 位 vs 64 位)以及是否启用特定特性(如异常处理)与构建静态库时所用的配置一致。否则,可能导致符号无法正确解析。 4. **函数声明与定义不一致** 检查头文件中对 `IMP_ISP_Tuning_*` 函数的声明是否与实际定义一致,包括返回类型、参数列表以及是否使用了 `extern "C"`(如果是 C++ 调用 C 代码)。 5. **依赖库未链接** `libppsmedia.a` 可能依赖于其他库(如 `libimp_isp.a` 或 `libhardware.a`)。确保所有依赖库都被正确链接到最终的可执行文件中。 6. **构建环境配置问题** 如果使用构建系统(如 CMake、Makefile),请检查是否正确配置了 `CMAKE_CXX_FLAGS`、`CMAKE_EXE_LINKER_FLAGS` 或 `LDFLAGS`,以确保所有必要的库路径和依赖项被正确传递给链接器。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值