【问题标题】:freebsd network program compilationfreebsd网络程序编译
【发布时间】:2012-12-17 18:05:22
【问题描述】:

我正在尝试在 freebsd 8 上编译一些简单的网络程序并遇到编译问题。我正在创建一个简单的客户端-服务器程序,但没有编译来自网络的功能或结构。

例如。我使用标准 socket() 调用来创建一个套接字,但我遇到了一个错误“被调用的对象套接字不是一个函数”。

如果我删除网络代码,那么我的玩具程序就会编译。为简单起见,我只是举了一个无法编译的简单示例。 :

#include <stdio.h>                        
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
void main(){
 int socket = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
 printf("Could create sockets without any issues.\n");
}

我用“cc toy_prog.c -lc”编译它并给了我提到的错误。

【问题讨论】:

  • “我的程序无法链接到库 (libc)”是什么意思?这是对代码设计/构造的限制还是您的意思是链接器找不到 libc 或?您的消息中包含的错误消息(格式正确)将使人们更容易帮助您。你知道make 和makefile 吗?只有最简单的项目才能在没有 makefile 的情况下通过。祝你好运。
  • 你是怎么调用socket的?它有签名int socket(int domain, int type, int protocol)。也许您可以提供您的代码摘录。
  • 请在您的问题中输入您的代码。祝你好运。

标签: unix networking freebsd bsd


【解决方案1】:

一个非常简单的错误。您已经定义了一个与您尝试调用的外部函数同名的局部变量 (socket)。试试下面的,你会得到同样的错误:

int f()
{
    return 0;
}

void main()
{
    int f = f();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    相关资源
    最近更新 更多