来自NULL的错误消息

时间:2014-11-02 02:06:34

标签: c raspberry-pi

我正在完成 C简介这本书,到目前为止它真的很棒。但是现在我正在尝试在我的RPi上运行以下程序,我遇到了以下错误:

include <stdio.h>
int test_func( char *s )
{
        if( s == NULL ) {
                fprintf( stderr,
                        "%s: recieved null pointer argument\n", __func__ );
                return -1;
        }
        /* ... */
}

错误:

/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
(.text+0x34): undefined reference to `main'
collect2: ld returned 1 exit status

这是什么意思?

1 个答案:

答案 0 :(得分:2)

每个C程序都需要一个main函数!否则程序不知道从哪里开始!所以这应该有效:

#include <stdio.h>

int test_func( char *s ) {
        if( s == NULL ) {
                fprintf( stderr,
                        "%s: recieved null pointer argument\n", __func__ );
                return -1;
        }
        /* ... */
}

int main() {

    //test_func(str)  call the function with the required parameters

    return 0;

}