Unable to bind LIBEVENT as C ++

Why this does not work, file test.c :

 #include <event.h> int main(void) { event_init(); return 0; } 

Then: gcc -o test.o -c test.c works fine, but

Link: g++ -o test -levent test.o produces

 test.o: In function `main': test.c:(.text+0x5): undefined reference to `event_init' collect2: ld returned 1 exit status 

Therefore, it cannot be linked as C++ . How to solve this? I need to link it as C++ and compile as C

+6
source share
1 answer

This question has been asked many times. On Linux, you must put libraries after objects and source files in a compilation command. Therefore try

 g++ -Wall -g -c mytest.cc g++ -Wall -g mytest.o -levent -o mytest 

Avoid calling your test program test , which is an already installed utility or shell.

As a beginner, remember to always compile all warnings given by -Wall , and to debug -g and learn how to use gdb

+9
source

Source: https://habr.com/ru/post/901828/


All Articles