如何(确切地)更改 GCC 目录搜索路径?

How(exactly) do I change the GCC directory search path?

好的,这是我要编译的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <net/sctp.h>


#define MAX_BUFFER 1024

void die(char *s)
{
      perror(s);
      exit(1);
}


int main(int argc, char **argv)
{

  int    connector,flags,r;
  u_int  port;
  struct hostent*        host;
  struct in_addr         in;
  struct sockaddr_in     rmaddr;
  struct sctp_initmsg    initmsg;
  struct sctp_sndrcvinfo sinfo;
  struct sctp_event_subscribe events; 
  bool   connected = false;   
  char   buffer[MAX_BUFFER];
  char*  exit = "quit";

  if(argc!=2) {
        printf("Usage: %s ipaddress\n", argv[0]);
    return -1;
  }



  if((connector = socket(AF_INET,SOCK_STREAM, IPPROTO_SCTP))<0){
      perror("socket");
      return -1;
   }



  printf("Enter the port number you wish to connect(on): ");
  scanf("%u", &port);
  printf("\n");

  if(port==0){
              printf("ERR0R: Port number must be between 1 & 65,535\n");
              printf("\n");
              printf("Enter the port number you wish to connect(on): ");
              scanf("%u", &port);
              printf("\n");        
  }


  memset( &initmsg, 0, sizeof(initmsg) );
  initmsg.sinit_num_ostreams = 3;
  initmsg.sinit_max_instreams = 3;
  initmsg.sinit_max_attempts = 2;
  if(setsockopt(connector,IPPROTO_SCTP,SCTP_INITMSG,&initmsg,sizeof(initmsg))<0){
       perror("setsockopt");
       return -1;
  }

  bzero( (void *)&rmaddr, sizeof(rmaddr) );
  rmaddr.sin_family = AF_INET;
  inet_pton(AF_INET, argv[1], &rmaddr.sin_addr);
  rmaddr.sin_port = htons(port);



  connect(connector,(struct sockaddr*)&rmaddr,sizeof(rmaddr));

       connected=true;
       memset( (void *)&events, 0, sizeof(events) );
       events.sctp_data_io_event = 1;
       setsockopt(connector, SOL_SCTP, SCTP_EVENTS,(const void *)&events, sizeof(events));
       printf("\n");
       printf("Connected to host: %s",argv[1],"on port %u",port);
       printf("     type 'quit' to disconnect\n");
       printf("\n");



  while(connected==true){

       int nbs;
       int nbr = 0;
       int flags = MSG_NOSIGNAL;
       printf(">");
       scanf("%s",buffer);
       printf("\n");

       sinfo.sinfo_flags = flags;

       nbs = send(connector,(void*)&buffer,sizeof(buffer),flags);        



       printf("\n");
       printf("# bytes sent %i\n", nbs);
       printf("\n");

       if(nbs<0){
        perror("sendmsg");
            close(connector);
            return -1;
       }

       while(nbr < nbs){
         socklen_t len = sizeof(rmaddr);
         nbr = recv(connector,(void*)&buffer,sizeof(buffer),flags);


         if(nbr<0){
               perror("recvmsg");
               close(connector);
               return -1;
         }else{
           printf(">>");
               printf("%s\n",buffer);
               printf("\n");
         }

       }

  }

}

当我输入命令 "gcc sctp_ec.c" 时,我得到以下输出:

-*- mode: compilation; default-directory: "/usr/lib/gcc/x86_64-linux-gnu/4.8.4/include/" -*-
Compilation started at Sun Aug 27 12:43:50

gcc sctp_ec.c
In file included from sctp_ec.c:10:0:
/usr/include/net/sctp.h:55:22: fatal error: net/ipv6.h: No such file or directory
compilation terminated.

Compilation exited abnormally with code 1 at Sun Aug 27 12:43:50

所以我知道问题出在哪里了。 GCC 编译器在错误的目录中搜索!我希望它在路径中搜索文件:/usr/lib/gcc/x86_64-linux-gnu/4.8.4/include 而不是 /usr/include。我尝试使用 -I、-Idir 和 -isystem 命令但无济于事。使用 -isystem,它会在这两个路径中进行搜索,并且存在定义冲突。那么我这里要怎么做才能让GCC/emacs24程序永久性的在.c代码文件所在的第一个路径中搜索呢?

FTR 我是 运行 emacs24 和 Linux Mint 18.1 上的 GCC。

使用这些命令行选项之一:

> -I dir
> -iquote dir
> -isystem dir
> -idirafter dir

如果您确实需要更改系统目录的搜索顺序,请使用 -nostdinc and/or -isystem 选项。

如果您将环境变量 C_INCLUDE_PATH 设置为搜索路径上您想要的目录列表,它将是永久性的(在您的 .profile 或 .login 文件中设置它,具体取决于您的 shell).该值应该是您要搜索的以冒号分隔的目录列表。