Unresolved Symbol (转)

本文探讨了在编程中遇到的未解析符号错误,通常发生在模块导入、预处理器指令、函数调用、头文件包含和命令行编译阶段。通过分析这些问题的常见原因和解决策略,帮助开发者诊断和修复这类编译错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to avoid the unresolved symbols error
If you keep getting an unresolved symbols error when using ALSA modules, the solution is very simple: Clean the kernel's source tree.

Change directory to the kernel source tree. If you want to keep the same config, I advise :

cp .config /tmp (not inside the current directory, it will get erased)
make mrproper
cp /tmp/.config .
make oldconfig
make dep
make bzImage
make modules
make modules_install
- Copy your new kernel image file bzImage to your boot device location as you'd normally do.

Then, recompile ALSA.

I know that this is not directly ALSA related, but it could take place
in the FAQ, as it definitely prevents ALSA from working.

Try this: In the alsa-driver directory,

rm config.cache
./configure [your options]
make clean
make
and then, as root, do:
make install
rmmod -a /_ these make sure no old modules are hanging around in memory
rmmod -a /
Maybe some partially-compiled files are left over from a previous attempt.
Remove all of the ALSA kernel modules before you do "make install". Do a
"find /lib/modules/`uname -r` -name 'snd*.o'" to make sure they're all gone.


On Thu, 8 Mar 2001, Narayana, Venkat A. wrote:

> Hi,
> I am learning to write kernel modules, and while experimenting
> with a simple module, i got
> " hello.o: unresolved symbol printk_Rsmp_1b7d4074" error
> while loading this module via insmod hello.o command.
>
> I noticed that /proc/ksyms contains printk symbol.
>
> What is that i am doing which is not correct?
> Help me out.

As other people have pointed out this has to do with versioning.

The simple answer to the question is that you need to include modversions.h
before the header file for printk if you want the module to load into a kernel with CONFIG_MODVERSIONS turned on.

You could do this in two ways:
  • in each of your c files, at the top (before you #include linux/kernel.h), you could have:
#ifdef CONFIG_MODVERSIONS
#include <linux/modversions.h>
#endif

  • or in your makefile, you could have
ifdef CONFIG_MODVERSIONS
CPPFLAGS += -include /usr/src/linux/modversions.h
endif



Now, I'll try and explain how it all works. (Jay, a section on this is definitely needed in the module programming guide ;).

Okay, this can be a bit difficult to explain, but I'll give it a go. I've probably got some of it wrong. Someone will correct me.

(all this assumes CONFIG_MODVERSIONS is turned on)

  • the kernel is compiled with -include /usr/src/linux/modversions.h. What this effectively means is that modversions.h is included at the top of every c file in the kernel.
  • so what does this do? Well, if you have a look at modversions.h, it includes loads of .ver files. Each of these files have loads of lines like (in ksyms.ver)
#define __ver_printk    1b7d4074
#define printk  _set_ver(printk)

this winds up having a #define along the line of

#define printk printk_R1b7d4074

  • so what does this do? Well, now everywhere printk is mentioned it gets
replaced by printk_R1b7d4074 by the preprocessor. So when the kernel is compiled
there is no such function as printk, there is only one called printk_R1b7d4074.

  • so if you want to write a module that uses the 'printk' function(sorry, I mean the printk_R1b7d4074 function) you're going to have to include modversions.h before printk is defined.


Another question you might ask is how the .ver files get generated?

  • well the basic command is along the lines of
     gcc -E -D__GENKSYMS__ <the-c-file> | genksys -k <your-kernel-version> > <your-ve
r-file>

  • the gcc command puts the c file through the preprocessor with __GENKSYMS__ defined
  • the output of this is passed through to genkyms which generates output like
#define __ver_printk    1b7d4074
#define printk  _set_ver(printk)

where the 1b7d4074 depends on the kernel version you supply.


Hi,

I have gone through an alsa compilation which went well, but the loading of the module came back with the following error :

     /lib/modules/2.2.17/misc/snd.o: unresolved symbol unregister_sound_dsp
     /lib/modules/2.2.17/misc/snd.o: unresolved symbol register_sound_dsp
     /lib/modules/2.2.17/misc/snd.o: unresolved symbol
     unregister_sound_special
     /lib/modules/2.2.17/misc/snd.o: unresolved symbol register_sound_special
     /lib/modules/2.2.17/misc/snd.o: insmod /lib/modules/2.2.17/misc/snd.o
     failed
     /lib/modules/2.2.17/misc/snd.o: insmod snd-cs4236 failed

I then went to the FAQ which said that it was because my kernel was incorrectly configured andalso because I had missed out the soundcore code (CONFIG_SOUND=y).

I was surprised because I had just recompiled that kernel, ensuring that I had added the right options.

Apparently -- I noticed this on some kernel mailing lists -- the usage of the kernel modversions facility (CONFIG_MODVERSIONS) is not always correctly taken into account by the fastdep kernel makefiles reconfiguration system.

The result is weird symbol names for some symbols.


要在龙芯CPU上安装VSCode,首先需要配置Loongnix系统的yum源,然后安装VSCode。具体步骤如下: 1. 配置Loongnix系统的yum源。可以按照引用\[1\]中提到的步骤进行配置。 2. 下载并安装VSCode。可以从VSCode官网(引用\[2\]中提供的链接)下载适用于Ubuntu系统的安装包。 3. 安装依赖库。根据引用\[1\]中的描述,需要编译libpng16.so.16并将其复制到安装目录。 4. 复制动态库。根据引用\[1\]中的描述,将编译好的动态库复制到安装目录。 5. 启动VSCode。根据引用\[1\]中的描述,可以通过命令行或图形界面启动VSCode。 请注意,以上步骤是基于引用\[1\]中提供的信息,适用于在龙芯CPU上安装VSCode的一般步骤。具体操作可能会因系统版本和配置而有所不同,建议参考相关文档或官方指南以获得更准确的安装步骤。 #### 引用[.reference_title] - *1* [linux安装vscode(中标麒麟+龙芯CPU)](https://blog.csdn.net/junxuezheng/article/details/103637575)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [迅为龙芯2K1000开发板虚拟机ubuntu安装vscode](https://blog.csdn.net/mucheni/article/details/121418004)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [龙芯平台安装Visual Studio Code(VSCode)](https://blog.csdn.net/ciji4412/article/details/100594256)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值