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

如何(准确地)更改GCC目录搜索路径?,c,linux,gcc,emacs24,C,Linux,Gcc,Emacs24,好的,下面是我试图编译的代码: #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

好的,下面是我试图编译的代码:

#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编译器正在错误的目录中搜索!我希望它在路径:/usr/lib/gcc/x86_64-linux-gnu/4.8.4/include中搜索文件,而不是/usr/include。我尝试使用-I、-Idir和-isystem命令,但没有效果。使用-isystem,它会在这两个路径中搜索,并且存在定义冲突。那么,我在这里要做什么来永久性地将GCC/emacs24程序更改为只在.c代码文件所在的第一个路径中搜索


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

使用以下命令行选项之一:

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

如果确实需要更改系统目录的搜索顺序,请使用
-nosdinc
和/或
-issystem
选项

使用以下命令行选项之一:

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

如果确实需要更改系统目录的搜索顺序,请使用
-nosdinc
和/或
-issystem
选项

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

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

有两个选项:makefile或将为您创建它的东西。我个人更喜欢日食。我不使用emacs,所以不能提供任何建议。有两个选项:makefile或为您创建它的东西。我个人更喜欢日食。我不使用emacs,因此无法提供任何建议。如何在.profile或.login文件中设置它?这听起来像是我要找的。你只需要使用一个文本编辑器(vi或emacs是Unix系统上的典型编辑器)。您可能将bash用于shell,因此您希望添加行
export C\u INCLUDE\u PATH=“/PATH/to/dir1:/PATH/to/dir2:/other/dir”
,然后运行命令
%.~/。profile
(是的,这是一个“.”),使其在当前shell中生效。它将自动发生在以后的所有shell中,您可以开始使用。我应该在.profile或.login文件中设置它吗?这听起来像是我要找的。你只需要使用一个文本编辑器(vi或emacs是Unix系统上的典型编辑器)。您可能将bash用于shell,因此您希望添加行
export C\u INCLUDE\u PATH=“/PATH/to/dir1:/PATH/to/dir2:/other/dir”
,然后运行命令
%.~/。profile
(是的,这是一个“.”),使其在当前shell中生效。它将自动发生在您以后启动的所有shell中