programing

mysql.h 파일을 찾을 수 없습니다.

oldcodes 2023. 11. 5. 14:59
반응형

mysql.h 파일을 찾을 수 없습니다.

우분투 12.04에 c++와 mysql 사이의 연결을 설치하려고 합니다. mysql-client, mysql-server, libmysqlclient15-dev, libmysql+-dev를 설치했는데 코드를 컴파일하려고 하면 오류가 발생했습니다.mysql.h there is no such file. 폴더를 찾아보니 mysql.h 파일이 있는데 왜 찾을 수 없는지 이해할 수 없습니다.여기 제 코드가 있습니다.

 /* Simple C program that connects to MySQL Database server*/
    #include <mysql.h>
    #include <stdio.h>

    main() {
      MYSQL *conn;
      MYSQL_RES *res;
      MYSQL_ROW row;

      char *server = "localhost";
      char *user = "root";
      //set the password for mysql server here
      char *password = "*********"; /* set me first */
      char *database = "Real_flights";

      conn = mysql_init(NULL);

      /* Connect to database */
      if (!mysql_real_connect(conn, server,
            user, password, database, 0, NULL, 0)) {
          fprintf(stderr, "%s\n", mysql_error(conn));
          exit(1);
      }

      /* send SQL query */
      if (mysql_query(conn, "show tables")) {
          fprintf(stderr, "%s\n", mysql_error(conn));
          exit(1);
      }

      res = mysql_use_result(conn);

      /* output table name */
      printf("MySQL Tables in mysql database:\n");
      while ((row = mysql_fetch_row(res)) != NULL)
          printf("%s \n", row[0]);

      /* close connection */
      mysql_free_result(res);
      mysql_close(conn);
    }

작동은 되었지만, 지금은 다음과 같은 또 다른 오류에 직면해 있습니다.

mysql.c: In function ‘main’:
mysql.c:21: warning: incompatible implicit declaration of built-in function ‘exit’
mysql.c:27: warning: incompatible implicit declaration of built-in function ‘exit’
/tmp/ccinQBp8.o: In function `main':
mysql.c:(.text+0x3e): undefined reference to `mysql_init'
mysql.c:(.text+0x5e): undefined reference to `mysql_real_connect'
mysql.c:(.text+0x70): undefined reference to `mysql_error'
mysql.c:(.text+0xa5): undefined reference to `mysql_query'
mysql.c:(.text+0xb7): undefined reference to `mysql_error'
mysql.c:(.text+0xe7): undefined reference to `mysql_use_result'
mysql.c:(.text+0x11c): undefined reference to `mysql_fetch_row'
mysql.c:(.text+0x133): undefined reference to `mysql_free_result'
mysql.c:(.text+0x141): undefined reference to `mysql_close'
collect2: ld returned 1 exit status

mysql.h에서 파일을 전송합니다.libmysqlclient-devUbuntu 패키지 위치:/usr/include/mysql/mysql.h.

이것은 컴파일러의 표준 검색 경로가 아닙니다./usr/include입니다.

일반적으로 사용하는 방법은mysql.h다음과 같이 코드에 헤더를 입력합니다.

#include <mysql/mysql.h>

소스에 디렉터리 오프셋을 지정하지 않으려면 다음을 전달할 수 있습니다.-I추가 포함 검색 디렉토리를 지정하기 위해 gcc(사용 중인 경우)로 플래그를 지정하면 기존 코드를 변경할 필요가 없습니다.

예를 들면

gcc -I/usr/include/mysql ...

쓰임새만

$ apt-get install libmysqlclient-dev 

최신 libmysqlclient18-dev를 자동으로 꺼냅니다.

이전 버전의 libmysqlclient-dev(15개 정도)는 mysql.h를 /usr/local/include 등과 같은 이상한 위치에 두는 것을 보았습니다.

그렇지 않으면, 그냥.

$ find /usr/ -name 'mysql.h' 

그리고 당신의 폴더 경로를 입력합니다.mysql.h당신의 make file에 -I flag를 넣었습니다.깨끗하지는 않지만 작동할 것입니다.

CentOS/RHEL의 경우:

yum install mysql-devel -y

이것은 나에게 효과가 있었습니다.

$ gcc dbconnect.c -o dbconnect -lmysqlclient
$ ./dbconnect

- lmysqlclient는 필수입니다.

그리고 저는 -I 컴파일 플래그를 사용하는 대신 다음과 같은 표기법을 사용하는 것을 추천합니다.

#include <mysql/mysql.h>

아마 여러 유닉스 시스템에서 /usr/include/mysql에서 찾을 수 있는 mysql 헤더에 대한 경로를 포함하지 않았을 것입니다.이 게시물을 보세요, 도움이 될지도 모릅니다.

그런데, 위에 있는 사람의 질문과 관련해서, 통사적 구성에 관한 것입니다.~/.vimrc에 다음을 추가할 수 있습니다.

let b:syntastic_c_cflags = '-I/usr/include/mysql'

github에서 개발자들의 wiki 페이지를 언제든지 확인할 수 있습니다.맛있게 드세요.

mysql.h 파일이 어디에 있는지 컴파일러에게 알려주어야 합니다.컴파일하기 전에 헤더에 대한 경로를 제공하여 이 작업을(를) 수행할 수 있습니다.IDE에는 이러한 경로를 제공할 수 있는 설정이 있습니다.

링크는 컴파일하는 동안 사용할 옵션에 대한 자세한 정보를 제공합니다.

두번째 문제 라이브러리를 연결해야 합니다.링커는 당신이 사용하는 mysql 함수에 대한 구현이 있는 라이브러리 파일이 어디에 있는지 알아야 합니다.

링크는 라이브러리를 연결하는 방법에 대한 자세한 정보를 제공합니다.

이 gcc -I/usr/include/mysql *.c -L/usr/lib/mysql -lmysql 클라이언트 -o *를 사용해 보십시오.

Eclipse IDE를 사용하시는 분들께.

mysql clientmysql server 그리고 어떤 mysql dev libraries와 함께 전체 MySql을 설치한 후,

Eclipse IDE에 다음 사항을 알려야 합니다.

  • mysql.h를 찾을 위치
  • libmysql 클라이언트 라이브러리를 찾을 위치
  • libmysql 클라이언트 라이브러리를 검색하는 경로

이것이 당신이 그것을 어떻게 할 것인가 입니다.

mysql.h를 추가하는 방법

1.GCC C 컴파일러 -> 포함 -> 경로(-l) 포함 후 +를 클릭하여 mysql에 경로를 추가합니다.h 제 경우 /usr/include/mysql 이었습니다.

enter image description here

mysqlclient 라이브러리 및 검색 경로를 where mysqlclient 라이브러리에 추가하려면 3단계4단계를 참조하십시오.

2.GCC C Linker -> Libraries -> Libraries(-l)를 클릭한 다음 +를 클릭하고 mysqlcient를 추가합니다.

enter image description here

3.GCC C Linker -> Librarys -> Library search path (-L)를 클릭한 다음 검색 경로mysqlcient에 추가합니다. 경우에는 64비트 Linux OS와 64비트 MySQL Database를 사용하기 때문에 /usr/lib64/mysql이었습니다.

그렇지 않으면 32비트 Linux OS를 사용하는 경우 /usr/lib/mysql에서 찾을 수 있습니다.

enter image description here

이거 나한테 통했어요.

yum install mysql

mysql client를 설치한 후

pip install mysqlclient

언급URL : https://stackoverflow.com/questions/14604228/mysql-h-file-cant-be-found

반응형