2017-03-16 1 views
0

gcc server.c -I /pwdmanlib/src -lssl -lcrypto -o server include가 내 src 파일 (헤더 필요 등)이고 나머지는 필수 ssl 라이브러리입니다. 나는 GCC에서 다음과 같은 출력을 얻고있다 :는 openssl 라이브러리를 사용하는 C 프로그램을 컴파일 할 수 없습니다.

In file included from server.h:49:0, 
       from server.c:39: 
/pwdmanlib/src/util/constants.h:30:0: warning: "LINE_MAX" redefined 
#define   LINE_MAX    2048 
^ 
In file included from /usr/include/limits.h:147:0, 
       from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:168, 
       from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h:7, 
       from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:34, 
       from /pwdmanlib/src/util/constants.h:26, 
       from server.h:49, 
       from server.c:39: 
/usr/include/x86_64-linux-gnu/bits/posix2_lim.h:81:0: note: this is the location of the previous definition 
#define LINE_MAX _POSIX2_LINE_MAX 
^ 
In file included from server.c:39:0: 
server.h: In function ‘start_server’: 
server.h:126:34: warning: comparison between pointer and integer 
    if (p == NULL || listen_sock == NULL) { 
           ^
In file included from server.c:39:0: 
server.h: In function ‘routeClient’: 
server.h:394:29: warning: passing argument 1 of ‘sendall’ makes pointer from integer without a cast [-Wint-conversion] 
       if (sendall(worker_sock, resp_data, fileLen) == -1) { 
          ^
In file included from server.c:39:0: 
server.h:70:5: note: expected ‘SSL * {aka struct ssl_st *}’ but argument is of type ‘int’ 
int sendall(SSL *ssl, char *buf, ssize_t *len); 
    ^
/tmp/ccubinQD.o: In function `InitSSL': 
server.c:(.text+0x1305): undefined reference to `OPENSSL_init_ssl' 
server.c:(.text+0x1314): undefined reference to `OPENSSL_init_ssl' 
server.c:(.text+0x1323): undefined reference to `OPENSSL_init_crypto' 
/tmp/ccubinQD.o: In function `InitCTX': 
server.c:(.text+0x1333): undefined reference to `TLS_server_method' 
server.c:(.text+0x1350): undefined reference to `SSL_CTX_set_options' 
collect2: error: ld returned 1 exit status 

은 내가 SSL 라이브러리의 OPENSSL_init_ssl 함수 호출을 발견하고는 분명히 포함되어지고 있지만, 라이브러리에 다른 참조에 의해 발견 될 수 없다? 은 내 프로그램에서 아래의 지정을 포함 :

ssl_funcs.h

#include <openssl/bio.h> 
#include <openssl/ssl.h> 
#include <openssl/err.h> 
#include <openssl/crypto.h> 

server.h

#include <netdb.h> 
#include <arpa/inet.h> 
#include <netinet/in.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <errno.h> 
#include <signal.h> 
#include <fcntl.h> 
#include <sys/wait.h> 
#include <unistd.h> 

#include "util/oop.h" 
#include "util/stringops.h" 
#include "util/constants.h" 
#include "fawkes_proto.h" 
#include "crypto/ssl_funcs.h" 

server.c

#include <netdb.h> 
#include <arpa/inet.h> 
#include <netinet/in.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <errno.h> 
#include <signal.h> 
#include <fcntl.h> 
#include <sys/wait.h> 
#include <unistd.h> 

#include "server.h" 
#include "util/constants.h" 
+0

'server.h : 70 : 5 : 참고 : 예상 'SSL의 * {일명 구조체 ssl_st *}'하지만 인수는 그 int'' 하나를보고하지 않는 '유형 인 조금 좋아. 코드로 이러한 문제를 해결해야합니다. 잘 쓰여진 코드는 경고없이 컴파일되어야합니다. – Havenard

답변

2

와 동적 라이브러리에 연결 -l 옵션은 반드시 발생해야합니다. 마지막, 다른 모든 옵션 뒤에 :

gcc server.c -I /pwdmanlib/src -o server -lssl -lcrypto 

이 외에도 코드의 경고를 해결해야합니다. 이로 인해 undefined behavior이 될 수 있습니다.

+0

빠른 답장을 보내 주셔서 감사합니다. -o 옵션을 이동했지만 여전히 컴파일 오류가 발생했습니다. cmd는 다음과 같습니다 :'gcc -I/pwdmanlib/src server.c -o server -L/usr/local/ssl/include/-L/usr/local/ssl/lib -lssl -lcrypto' 코드는 똑같이합니다. –

0

나 또한 그렇게 같은 연결 라이브러리에 대한 명시 적 대상 디렉토리로 컴파일 할 필요가 위의 대답 dbush에 추가 : 또한 gcc server.c -I/pwdmanlib/src -o server -L/usr/local/lib -lssl -lcrypto

, 나는 또한 CMake에서이을위한 솔루션 (I가 사용하는 시스템을 구축을 구현 내 프로젝트)를 제공하고 그 외에 다른 사람이 유용하다고 생각할 수도 있습니다. 이것은 단지 그것의 관련 부분입니다, 누군가가 cmake에 전체 src를 원한다면 나는 그것을 제공하는 것보다 더 행복 할 것입니다.

CMakeLists.txt

# Add libraries 
include_directories(${LOCAL_LIBS_DIR}) 
include_directories("/usr/local/lib") 
#link_directories("/usr/local/lib") 

add_library(ssl SHARED IMPORTED) # or STATIC instead of SHARED 
set_property(TARGET ssl PROPERTY IMPORTED_LOCATION "/usr/local/lib/libssl.so") 
add_library(crypto SHARED IMPORTED) # or STATIC instead of SHARED 
set_property(TARGET crypto PROPERTY IMPORTED_LOCATION "/usr/local/lib/libcrypto.so") 
#include_directories("/opt/openssl-1.1.0e") 

#find_package (my_library COMPONENTS REQUIRED component1 component2 OPTIONAL_COMPONENTS opt_component) 

# Define build targets and link libraries 
add_executable(main ${SOURCE_FILES}) 
target_include_directories(main PUBLIC /usr/include/openssl) 
target_link_libraries(main 
     PRIVATE ${Boost_LIBRARIES} 
     PRIVATE ${PostgreSQL_LIBRARIES} 
     PRIVATE ${cJSON_ROOT_DIR} 
#  PRIVATE ${CryptoPP_ROOT_DIR} 
#  PRIVATE ${Kore_ROOT_DIR} 
#  PRIVATE ${POCO_LIBRARIES} 
     PRIVATE ssl 
     PRIVATE crypto 
) 
관련 문제