0
그래서이 다음 코드 :-l : 정확한 라이브러리를 연결하지 libsomething.so.1.1.1
#include <pcre.h>
#include <stdio.h>
#include <string.h>
int main(const int argc, const char * const * const argv) {
if (argc != 3) {
fprintf(stderr, "Usage: %s reg_exp string\n", argv[0]);
}
const char * const reg_exp = argv[1];
const char * const string = argv[2];
const char * pcre_error_str;
int pcre_error_offset;
// Compile
pcre * const compiled = pcre_compile(reg_exp, 0, &pcre_error_str, &pcre_error_offset, NULL);
if (NULL == compiled) {
const int size = pcre_error_offset + 1;
char * const indent = (char*)malloc(size);
memset(indent, ' ', size);
indent[size - 1] = '\0';
fprintf(stderr, "Failed to compile: %s\n%s\n%s^\n", pcre_error_str, reg_exp, indent);
free(indent);
return EXIT_FAILURE;
}
// Optimise
pcre_extra * const extra = pcre_study(compiled, 0, &pcre_error_str);
if (NULL == extra) {
fprintf(stderr, "Failed to study: %s\n%s\n", pcre_error_str, reg_exp);
return EXIT_FAILURE;
}
// Match
int sub_strs[30];
const int status = pcre_exec(compiled, extra, string, strlen(string), 0, 0, sub_strs, 30);
if(status < 0) {
#define Case(code, msg) \
case code: \
fprintf(stderr, msg ": %s %s\n", reg_exp, string); \
break
switch(status) {
Case(PCRE_ERROR_NOMATCH, "String did not match the pattern");
Case(PCRE_ERROR_NULL, "Something was null");
Case(PCRE_ERROR_BADOPTION, "A bad option was passed");
Case(PCRE_ERROR_BADMAGIC, "Magic number bad (compiled re corrupt?)");
Case(PCRE_ERROR_UNKNOWN_NODE, "Something kooky in the compiled re");
Case(PCRE_ERROR_NOMEMORY, "Ran out of memory");
default: fprintf(stderr, "Unknown error: %s %s\n", reg_exp, string);
}
return EXIT_FAILURE;
}
// Win!
printf("Matched: %s %s\n", reg_exp, string);
return EXIT_SUCCESS;
}
다음 명령 라인을 구축 :
gcc -s -O3 -std=c11 -Werror -Wall -Wextra -o main main.c -l:libpcre.so.1.2.4
내가 만약 해당 링크가 아직 연결되어 있는지 검사하십시오. libpcre.so.1
:
$ ldd main
linux-vdso.so.1 (0x00007fff341fe000)
libpcre.so.1 => /usr/lib/libpcre.so.1 (0x00007fe90d508000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007fe90d165000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fe90cf49000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe90d777000)
$ objdump -x main | grep pcre
NEEDED libpcre.so.1
그러나 나는 PCRE의 특정 버전에 대해 -l:libpcre.so.1.2.4
으로 링크하고 싶습니다. 저장된 NEEDED 항목이`libpcre.so.1.2.4가 아닌 이유는 무엇입니까?
내가 작성 당시에 gcc
4.9.2
및 ldconfig
이 아치 리눅스 x86_64의에있어 :
$ ldconfig -p | grep pcre
libpcre32.so.0 (libc6,x86-64) => /usr/lib/libpcre32.so.0
libpcre32.so (libc6,x86-64) => /usr/lib/libpcre32.so
libpcre16.so.0 (libc6,x86-64) => /usr/lib/libpcre16.so.0
libpcre16.so (libc6,x86-64) => /usr/lib/libpcre16.so
libpcreposix.so.0 (libc6,x86-64) => /usr/lib/libpcreposix.so.0
libpcreposix.so (libc6,x86-64) => /usr/lib/libpcreposix.so
libpcrecpp.so.0 (libc6,x86-64) => /usr/lib/libpcrecpp.so.0
libpcrecpp.so (libc6,x86-64) => /usr/lib/libpcrecpp.so
libpcre.so.1 (libc6,x86-64) => /usr/lib/libpcre.so.1
libpcre.so (libc6,x86-64) => /usr/lib/libpcre.so
'-l (비표준가) 완전한 라이브러리 이름 때문에
내가 혼란스러워했다'단지 조회에 추가해야 어떤 파일 이름을 말한다 명부. 버전은 이후 단계에서 추가/제거됩니다. 예 : '-lpcre'로 링크하면'libpcre.so'가'libpcre.so.1'을 가리키면'libpcre.so.1.2.4'를 가리 킵니다. 그것은 일반적인 행동입니다. 표준에 따라 위임 될 수도 있습니다. 자신의 전체 라이브러리 이름을 제공하는 방법을 모르겠습니다 (ELF 결과를 패치하는 것 외). – keltar
@keltar, 감사합니다. –