ハードウェアの初期化用の ac ファイルと、そこからメソッドを呼び出す c++ ファイルがあります。g++ を使用してコンパイルしようとすると、次のようになります。
g++ testPegio.cpp -o testPeg
私は以下を取得します:
/usr/include/c++/4.6/chrono:35:0 からインクルードされたファイルで、testPegio.cpp:6 から: /usr/include/c++/4.6/bits/c++0x_warning.h:32:2: エラー: #error このファイルには、今後の ISO C++ 標準である C++0x のコンパイラとライブラリのサポートが必要です。このサポートは現在実験段階であり、-std=c++0x または -std=gnu++0x コンパイラ オプションで有効にする必要があります。
だから私はこれを試します:
g++ testPegio.cpp -o testPeg -std=c++0x
そして私は得る:
/tmp/cczOOOyb.o: 関数
main': testPegio.cpp:(.text+0xc): undefined reference to
pegio_init で collect2: ld が 1 つの終了ステータスを返しました
コードの重要なスニペットを次に示します。
pegio.h
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h> //used for uart
#include <fcntl.h> //used for uart
#include <termios.h> //used for uart
#include <string.h>
#include <string>
#define BAUD_RATE B1152000
#define BYTE_SIZE CS8
#define MAX_STRING_LEN 80
#define true 1
#define false 0
typedef int bool;
extern char pegio_init(void); // initialize serial port
extern char pegio_deinit(void); // deinitialize serial port
extern void pegio_serial_write(char inStr[MAX_STRING_LEN]); // serial write method
extern void pegio_serial_read(char * str); // serial read method
extern bool charCheck(char ch); // character check
pegio.c
#include "pegio.h"
int uart0_filestream = -1;
// ** INITIALIZE THE UART **
char pegio_init(void)
{
uart0_filestream = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
if (uart0_filestream == -1)
{
//ERROR - Can't open serial port
printf("Error - Unable to open UART. Ensure it is not in use by another application\n");
}
struct termios options;
tcgetattr(uart0_filestream, &options);
options.c_cflag = BAUD_RATE | BYTE_SIZE | CLOCAL | CREAD; //<Set the baud rate
options.c_iflag = IGNPAR | ICRNL;
options.c_oflag = 0;
options.c_lflag = 0;
tcflush(uart0_filestream, TCIFLUSH);
tcsetattr(uart0_filestream, TCSANOW, &options);
return 0;
}
// ** DEINITIALIZE THE UART **
char pegio_deinit()
{
close(uart0_filestream);
return 0;
}
そして最後に、testPeg.cpp
extern "C" {
#include "pegio.h"
}
#include <iostream>
#include <chrono>
#include <stdlib.h>
int main()
{
int result = pegio_init();
return result;
}
何か案は??