Bonjour, je suis en train de développer une application avec des .c et des .h.

Voici mes codes:

Main

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
#include "driver_rs232.h"
 
int main(int argc, char *argv[])
{
    init_COM();
 
    return 1;
}
driver_rs232.h:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
#ifndef RS232_H
#define RS232_H
 
 
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
 
#define BAUDRATE B460800
#define MODEMDEVICE "/dev/ttyUSB0"
 
void signal_handler_IO (int status);
void init_COM();
 
#endif // RS232_H

driver_rs232.c:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "driver_rs232.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
 
int fd, res;
struct termios newtio;
struct sigaction saio;           /* definition of signal action */
char buf[4096];
 
int wait_flag;
 
 
void init_COM()
{
    fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY |O_NDELAY);
    if (fd <0) {perror(MODEMDEVICE); }//exit(-1); }
 
 
    /* install the signal handler before making the device asynchronous */
    __sigset_t t;
    saio.sa_handler = signal_handler_IO;
    saio.sa_mask = t;
    saio.sa_flags = 0;
    saio.sa_restorer = NULL;
    sigaction(SIGIO,&saio,NULL);
 
    /* allow the process to receive SIGIO */
    fcntl(fd, F_SETOWN, getpid());
    /* Make the file descriptor asynchronous (the manual page says only
               O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
    fcntl(fd, F_SETFL, FASYNC);
 
    //bzero(&newtio, sizeof(newtio));
    newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
    newtio.c_iflag = IGNPAR;
    newtio.c_oflag = 0;
 
 
    /* set input mode (non-canonical, no echo,...) */
    newtio.c_lflag = 0;
    newtio.c_cc[VTIME]    = 0;   /* inter-character timer unused */
    newtio.c_cc[VMIN]     = 0;   /* blocking read until 5 chars received */
 
    tcflush(fd, TCIFLUSH);
    tcsetattr(fd,TCSANOW,&newtio);
 
}
 
 
/***************************************************************************
* signal handler. sets wait_flag to FALSE, to indicate above loop that     *
* characters have been received.                                           *
***************************************************************************/
 
void signal_handler_IO (int status)
{
//    cout << "received SIGIO signal." << endl;
//    printf("received SIGIO signal.\n");
    wait_flag = 0;
}
Lors de la compilation,j'ai cette erreur:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
g++ -Wl,-O1 -o sans_titre main.o driver_rs232.o    -L/usr/lib -lQtCore -lpthread 
/usr/bin/ld: main.o: in function main:main.cpp(.text+0x7): error: undefined reference to 'init_COM()'
collect2: ld returned 1 exit status
Je précise que je suis sous Linux, je compile avec QtCreator.

Quelqu'un aurait une idée de la source du problème ?

D'avance merci.