を結ぶ私はC++ ...私は別のソースにCでいくつかの機能を宣言しようとしているC++関数エラーの複数の宣言
を忘れて、必要なときに適切な.h
を含めているように見えます。それはOKをコンパイルします。リンカーがすでに定義されている機能について不平を言うリンク中に問題が発生します。
私はさらに、関数を宣言して実装を.c
でのみ実現しようとすると、関数をextern
として定義しようとしました。
これは私のコードの簡略説明です:
COMMON.H
#include <stdio.h>
module1.h
#include "common.h"
#ifndef MODULE1_H_
#define MODULE1_H_
int init(int option);
int open(char* db, char* username, char* password);
int get(int handler, int date[2], int time[2], int* data, int& rowsize, int& numrows);
int put(int handler, int* data, int& datasize, int& numrows);
int close(int handler);
int finalize();
#endif /* MODULE1_H_ */
module2.h
#include "common.h"
#ifndef MODULE2_H_
#define MODULE2_H_
int get1(int handler, int date, int time, int *data, int& datasize, int& rowsize);
int put1(int handler, int* data, int datasize);
#endif /*MODULE2_H_*/
module1.cpp
#include "module1.h"
int init(int option) { ... }
int finalize() { ... }
int get(int handler, int date[2], int time[2], int* data, int& rowsize, int& numrows) {
....
}
...
module2.cpp
#include "module1.h"
#include "module2.h"
int get1(int handler, int date, int time, int* data, int rowsize) {
int daterange[2]={date,date};
int timerange[2]={time,time};
int rsize, numrows, result;
result=get(handler, daterange,timerange, data, rsize, numrows);
rowsize=rsize;
if(numrows!=1) printf("Uh oh...\n");
return result;
}
...
&コンパイルリンケージ:
g++ -o module1.o -c module1.cpp
g++ -o module2.o -c module2.cpp
g++ -fPIC -shared -o library.so module1.o module2.o
私が言ったように、それはOKをコンパイルします。問題はリンケージ中です。リンカは、module1.h
の2つの実装された関数があると見ています:module1.h
を含むものからmodule1.cpp
に含まれています。もう1つはmodule1.h
と一緒にmodule2.h
と一緒にmodule2.cpp
に含まれています。
私は関数が宣言されるはずであることは知っていますが、私は明らかにfaux-pasをやっています。 誰かがそれがどこであるかを指摘できますか?前もって感謝します。
実際のエラーメッセージをリンカーから含めてください。 – SoapBox
質問に特定のリンカーエラーメッセージを追加することをお勧めします。関数名が組み込み関数と競合する可能性があります。 –
実際のコードを "include/ifx2f.h:215"から投稿し、そのヘッダの複数のインクルードガード –