1. 程式人生 > >學習筆記:relocation R_X86_64_32 against `.rodata' can not be used when making a shared object;

學習筆記:relocation R_X86_64_32 against `.rodata' can not be used when making a shared object;

解決多個.a靜態庫,連結成一個.so動態庫出現: 

relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; 的錯誤。

我的總目標是:寫一個mainApi.cpp的檔案,這個檔案提供API給外部使用者使用。mainApi.cpp需要依賴其他模組生成的靜態庫(在lib檔案下)。將mainApi.cpp編譯

連結成一個.so動態庫共外部使用。在編譯的時候出現relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; 的錯誤。

原因是因為生成靜態庫時沒有加 -fPIC 選項。

問題解決是如下(紅色字型部分):

ifeq ($(MK_STATIC_LIB),no)
    TARGET = libSendMsgModel.so
    CFLAGS += -fPIC             # 靜態庫連結成.so動態庫,編譯靜態庫的時候需要加 -fPIC這個引數。
else
    TARGET = libSendMsgModel.a
endif

看下最後的實現目標(在主目錄下生成libSendMsgModel.so檔案):

看看lib下的檔案:

主目錄下的Makefile:

XX = g++
AR = ar
ARFLAG = -rcs
CFLAGS = -g 

CLIBS = -L./lib/ -lSender -lReceiver -lResponser -lListener -lLogout -lpthread -lrt

SUBDIRS = ./logout ./receiver ./responser ./sender ./listener 
 # INCLUDE = a.h b.h ... can't be defined like "INCLUDE = ./*.h"
INCLUDES = $(wildcard ./include/*.h ./sender/*.h ./receiver/*.h ./responser/*.h)
#指定標頭檔案目錄,程式碼中就不需要把標頭檔案的完整路徑寫出來了
INCLUDE_DIRS = -I./include -I./sender/ -I./receiver/ -I./responser/ -I./listener -I./logout 

OBJECTS = mainApi.o

export XX CFLAGS AR ARFLAG

ifeq ($(MK_STATIC_LIB),no)
    TARGET = libSendMsgModel.so
    CFLAGS += -fPIC             # 靜態庫連結成.so動態庫,編譯靜態庫的時候需要加 -fPIC這個引數。
else
    TARGET = libSendMsgModel.a
endif

ifeq ($(MK_STATIC_LIB),no)
$(TARGET) : $(OBJECTS) $(SUBDIRS)
	$(XX) $(CFLAGS) -shared -fPIC $< -o 
[email protected]
$(CLIBS) # $< 表示依賴列表的第一個 也就是 $(OBJECTS) $(OBJECTS) : %.o : %.cpp $(XX) -c $(CFLAGS) $< -o [email protected] $(INCLUDE_DIRS) else $(TARGET) : $(OBJECTS) $(SUBDIRS) $(AR) $(ARFLAG) [email protected] $< # $< 表示依賴列表的第一個 也就是 $(OBJECTS) $(OBJECTS) : %.o : %.cpp $(XX) -c $(CFLAGS) $< -o
[email protected]
$(INCLUDE_DIRS) endif $(SUBDIRS):ECHO +$(MAKE) -C [email protected] ECHO: @echo $(SUBDIRS) @echo begin compile .PHONY : clean clean: for dir in $(SUBDIRS);\ do $(MAKE) -C $$dir clean||exit 1;\ done rm -rf $(TARGET) $(OBJECTS) ./lib/*.a

相關推薦

學習筆記:relocation R_X86_64_32 against `.rodata' can not be used when making a shared object;

解決多個.a靜態庫,連結成一個.so動態庫出現:  relocation R_X86_64_32 against `.rodata' can not be used when making a s

Build error: relocation R_X86_64_32 against `ff_a64_muxer' can not be used when making a shared obje

編譯 opencv with ffmpeg 出錯: 能用 make 儘量別用 ,make -j8 開多執行緒 不然出錯都不知道哪出錯 進入 ffmpeg/: I had to recompile

can not be used when making a shared object; recompile with -fPIC

錯誤資訊 /usr/bin/ld: crypto/libraven_crypto.a(crypto_libraven_crypto_a-blake.o): relocation R_X86_64_32 against `.rodata' can not be used when making a

內網編譯安裝net-snmp,提示relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a share

    公司需要在內網環境下(不能訪問外網),通用原始檔編譯安裝net-snmp,監控內網伺服器的引數資訊,但是在編譯,即make的情況下,出現了Error,因為對linux的深度使用不是很熟悉,所以經過幾天的測試才找到解決辦法,下面是錯誤:    /usr/bin/l

【link】relocation R_X86_64_32 against `text' cannot be used when making a shared object

DATE: 2018.11.19 1、參考 2、問題描述 relocation R_X86_64_32 against `text' cannot be used when making a sha

ubuntu opencv 編譯失敗 relocation R_X86_64_32 against `.rodata.str1.1'

ubuntu14.04安裝配置FFmpeg+opencv-3.1.0+python 呼叫opencv模組 這次因為寫python時候要調opencv的函式,在ubuntu14.04安裝了opencv,中間出現一個安裝錯誤: /usr/bin/ld: /usr/local/

Partitioning can not be used stand-alone in query .. mysql 建立分割槽

今天遇到一個狗血的問題,Partitioning can not be used stand-alone in query near 'PARTITION BY RANGE  COLUMNS(stats_dt) (,其實是簡單的錯誤,建立mysql分割槽時,語句,寫錯了,在在之前,多了一個

jqGrid ---Grid can not be used in this ('quirks...

今天在使用jquery.jqGrid.min.js時 彈出錯誤提示  Grid can not be used in this ('quirks') mode! 檢視原始碼後發現 if(document.documentMode !== undefined ) {

Kotlin學習筆記:NotImplementedError: An operation is not implemented

// 自定義的一個介面 interface OnTestCallback{ fun onTest() } // 用快捷方法生成介面內的方法 setOnTestCallback(object :OnTestCallback{ ov

java學習筆記20170705 The origin server did not find a current representation for the target resource or

今天學習JSTL相關方面的知識,奈何寫在jsp裡面的東西,跑步起來。一直報錯。 主要目的:開啟jsp檔案,run on server 跑起來。 The origin server did not find a current representation for th

maven-web項目剛創建報錯:Description Resource Path Location Type JavaServer Faces 2.2 can not be installed : One or more cons

ati plugins tool com -a riff common margin led 解決:問題描述:maven項目出現如下錯誤JavaServer Faces 2.0 requires Dynamic Web Module 2.5 or newer..Maven

Value '0000-00-00' can not be represented as java.sql.Date解決辦法

解決 oca 返回 字段 color url mysq 使用 Coding java.sql.SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp 問題描

CLR via C#學習筆記-第四章-類型基礎-所有類型都從System.Object派生

回收 spa 操作 哈希 包括 生成 自動生成 返回 equals 4.1 所有類型都從System.Object派生 System.Object類型 運行時要求每個類型最終都從System.Object類型派生 也就是說,以下兩個類型定義完全一樣 //隱式派生自Syst

【Android】AS警告解決方法:String literal in setText can not be translated. Use Android resources instead.

轉載請註明出處,原文連結:https://blog.csdn.net/u013642500/article/details/80166941 【錯誤】 String literal in setText can not be translated. Use Android reso

【python學習筆記】37:認識Scrapy爬蟲,爬取滬深A股資訊

學習《Python3爬蟲、資料清洗與視覺化實戰》時自己的一些實踐。 認識Scrapy爬蟲 安裝 書上說在pip安裝會有問題,直接在Anaconda裡安裝。 建立Scrapy專案 PyCharm裡沒有直接的建立入口,在命令列建立(從Anaconda安裝後似乎自動就

java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

今天在使用 Mysql 中的一個 datetime 欄位時碰到了一個 Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp 異常,之前使用都沒有

關於springcloud中使用feign出現LinkedHashMap can not be cast to xxx 的解決方案

關於springcloud中使用feign出現LinkedHashMap can not be cast to xxx 的解決方案 個人公眾號 扯淡 解決方案 自定義FeignClient,覆蓋提供的FeignClient

報錯java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

報錯環境是maraiadb5.5所用的時間欄位是timestamp,mariadb5.6用的datetime的mariadb是不會報這個錯誤的 原配置為: spring.datasource.url=jdbc:mysql://10.44.100.217:3306/xxx_test?auto

JavaServer Faces 2.0 can not be installed解決方案

問題描述:maven專案出現如下錯誤 JavaServer Faces 2.0 requires Dynamic Web Module 2.5 or newer..Maven Java EE Configuration     Problem JavaServer Face

The file can not be loaded because it was created for another build target that is not compatible wi

03-23 14:35:05.274: E/Unity(5354): The file can not be loaded because it was created for another build target that is not compatible with this platfor