C와 함께 sqlite를 사용하려고합니다. 파이썬에서는이 작업을 수행하는 것이 쉽지만 C에서 동일한 작업을 수행하려고하면 오류가 발생합니다.sqlite를 연결하는 중 오류가 발생했습니다.
libsqlite in simulator and iOS compiling
하지만 단순히 텍스트 편집기를 사용하고, 그래서 나는 엑스 코드를 사용할 수 없습니다 (잘가, 내가 할 수있는,하지만 난 아니에요) :
나는이 발견했다. 내가#include <sqlite.h> // or "sqlite.h"
작업을 수행 할 때 나는 오류과 같이 얻을 :
Undefined symbols for architecture i386:
"_sqlite3_open", referenced from:
_main in ccb8OLfK.o
"_sqlite3_exec", referenced from:
_main in ccb8OLfK.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
당신이 내 코드를보고 싶은 경우에, 여기의 전부 :
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <string.h>
int main(void) {
/* variables */
// create value for storing return codes
int retval;
// the number of queries to be handled
int qnum;
// size of each query
int qsize;
// pointer
int ind;
// statement for fetching tables
sqlite3_stmt *stmt;
// pointer to sqlite3
sqlite3 *db;
// db name
char *home = getenv("HOME");
char *dbPath = strcat(home, "/Desktop/test.db");
/* connect and write */
// Try to connect to database (if fails, returns null)
retval = sqlite3_open(dbPath, &db);
if (retval) {
printf("\x1B[31;1mConnection failed.\x1B[0m\n");
exit(1);
} else {
printf("\x1B[32;1mConnected to Database.\x1B[0m\n");
}
// create table
char q[100] = "create table if not exists test (user text not null, psswd text not null);";
retval = sqlite3_exec(db, q, 0, 0, 0);
}
그것은 몇되지 않는있다 변수를 지금까지 (그리고 내가 멀리 얻을 수있는 경우) 테이블을 만듭니다 있지만 컴파일하고 잘 실행해야합니다.
저는 C (Java -> Python -> C)를 처음 사용했습니다. 어떻게 작동 시키나요?
이것은 정말 큰 고통처럼 보입니다. 그렇다면 sqlite3 헤더 파일을 다운로드하여 따옴표와 함께 포함시킬 수 있습니까? 파일을 연결하는 방법을 모르겠습니다.이 예비 테스트가 작동하기를 바랍니다.
좋아요, 저는 방금 집에서 만들었습니다. 그게 올바르게 작동할까요? ... Homebrew의 Cellar (/ usr/local/Cellar /)에있는 sqlite 디렉토리에 sqlite.h가 있습니다. – dylnmc
그럴 경우,'-lsqlite3'과 링크하거나 Xcode에 라이브러리를 포함하십시오. (AFAIK Xcode는 실제로 CoreData의 일부로 sqlite3을 지원해야하지만 아직 iOS의 해당 부분을 다루지 않았습니다.) – nneonneo
Xcode를 사용하지 않고 있습니다 ... 텍스트 편집기를 사용하고 있습니다. 헤더를 같은 디렉토리에 넣었지만 그걸 어떻게 처리해야할지 모르겠다. 나는 밤에 은퇴해야만 할 것이다. 도와 주셔서 감사합니다! – dylnmc