簡體   English   中英

Linux GCC Makefile 具有多個源和依賴項的共享庫

[英]Linux GCC Makefile a shared library with multply sources and dependencies

我在嘗試創建一個 Makefile 時遇到問題,該 Makefile 編譯多個源,僅生成一個共享庫並使用另一個主 function 文件制作一個 exe。

這些sorces也有依賴關系。

我的 Makefile 是

CC=gcc
CFLAGS=-Wall -g
BINS=libsensorMotor.so maintarget

all: $(BINS)

libsensorMotor.o: libsensorMotor.cpp sensorMotor.h Adafruit_ADS1015.cpp Adafruit_ADS1015.h wiringPiI2C.c wiringPiI2C.h enumADCGain.h
    $(CC) $(CFLAGS) -c libsensorMotor.cpp Adafruit_ADS1015.cpp wiringPiI2C.c

libsensorMotor.so: libsensorMotor.cpp sensorMotor.h 
    $(CC) $(CFLAGS) -fPIC -shared -o $@ libsensorMotor.cpp -lc

maintarget: maintarget.c
    $(CC) $(CFLAGS) -o $@ $^ -L. -lsensorMotor -pthread

clean:
    rm *.o $(BINS)

該腳本顯示錯誤:

 libsensorMotor.so  Undefined reference to 'functionXXXX'

maintarget 包含 main 並使用 libsensorMotor 作為共享庫。 libsensorMotor 依賴並包含所有 rest 文件

該錯誤提到了 libsensorMotor 從包含源中使用的所有功能。

我只需要生成一個正確的 libsensorMotor.so 就可以用作任何其他主文件的共享庫。 互聯網上有很多教程,但不清楚,奇怪和復雜,並沒有說明如何做到這一點簡單。

是不是Makefile的問題,干脆就行

gcc -pthread -lm -o maintarget maintarget.c libsensorMotor.cpp Adafruit_ADS1015.cpp 接線PiI2C.Z4A8A08F09D37B737956349038F

sends same error, the compiler not recongnice the function inside the pthread_create while compile C and C++ with gcc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM