net-snmp靜態(tài)編譯鏈接的獲取程序及生成執(zhí)行程序詳解
引言
由于在某些場(chǎng)景需要使用靜態(tài)鏈接的snmpwalk
或者其他程序,為了方便執(zhí)行文件的分發(fā),適配多版本系統(tǒng),所以需要自己編譯net-snmp
實(shí)驗(yàn)操作系統(tǒng)Ubuntu22 amd64
獲取程序
git clone
方式
$ git clone https://github.com/net-snmp/net-snmp.git
或者也可以依據(jù)tag
下載源碼包
生成Makefile
net-snmp
項(xiàng)目根路徑下面有一個(gè)configure
文件,可以用于生成Makefile
,命令執(zhí)行過(guò)程中會(huì)彈出一些輸入確認(rèn),直接回車(chē)確認(rèn)即可
$ ./configure --prefix=/tmp/snmp --disable-embedded-perl --without-perl-modules --disable-ucd-snmp-compatibility --disable-scripts
--prefix
參數(shù)指定文件安裝目錄到/tmp/snmp
需要禁用perl
相關(guān)模塊以及一些腳本,否則可能會(huì)遇到錯(cuò)誤如下
relocation R_X86_64_PC32 against symbol `netsnmp_ds_handle_config' can not be used when making a shared object; recompile with -fPIC
生成執(zhí)行程序
如果此時(shí)項(xiàng)目根目錄下面生成一個(gè)Makefile
,則表示configure
命令成功
執(zhí)行程序的源碼和生成的二進(jìn)制都在apps/
目錄下
$ make LDFLAGS="-static"
校驗(yàn)生成的二進(jìn)制執(zhí)行文件,發(fā)現(xiàn)不是靜態(tài)鏈接的
$ ldd apps/snmpwalk linux-vdso.so.1 (0x00007ffed71c1000) libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007ff639800000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff639400000) /lib64/ld-linux-x86-64.so.2 (0x00007ff639d7e000)
靜態(tài)編譯snmpwalk
發(fā)現(xiàn)在make snmpwalk
執(zhí)行的時(shí)候會(huì)產(chǎn)生兩條執(zhí)行命令,第一條是 gcc
包含-static
參數(shù),但是第二條沒(méi)包含
$ cd apps $ rm snmpwalk $ make snmpwalk /bin/bash ../libtool --mode=link gcc -static -g -O2 -DNETSNMP_ENABLE_IPV6 -fno-strict-aliasing -DNETSNMP_REMOVE_U64 -g -O2 -Ulinux -Dlinux=linux -Wall -Wextra -Wstrict-prototypes -Wwrite-strings -Wcast-qual -Wimplicit-fallthrough -Wlogical-op -Wundef -Wno-format-truncation -Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter -o snmpwalk snmpwalk.lo ../snmplib/libnetsnmp.la libtool: link: gcc -g -O2 -DNETSNMP_ENABLE_IPV6 -fno-strict-aliasing -DNETSNMP_REMOVE_U64 -g -O2 -Ulinux -Dlinux=linux -Wall -Wextra -Wstrict-prototypes -Wwrite-strings -Wcast-qual -Wimplicit-fallthrough -Wlogical-op -Wundef -Wno-format-truncation -Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter -o snmpwalk .libs/snmpwalk.o ../snmplib/.libs/libnetsnmp.a -lm -lssl -lcrypto
所以需要執(zhí)行命令如下,把make snmpwalk
的輸出的第二條命令粘貼下來(lái),手動(dòng)在gcc
后面加上-static
參數(shù)
$ rm snmpwalk $ gcc -static -g -O2 -DNETSNMP_ENABLE_IPV6 -fno-strict-aliasing -DNETSNMP_REMOVE_U64 -g -O2 -Ulinux -Dlinux=linux -Wall -Wextra -Wstrict-prototypes -Wwrite-strings -Wcast-qual -Wimplicit-fallthrough -Wlogical-op -Wundef -Wno-format-truncation -Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter -o snmpwalk .libs/snmpwalk.o ../snmplib/.libs/libnetsnmp.a -lm -lssl -lcrypto # 執(zhí)行的時(shí)候會(huì)產(chǎn)生告警信息如下,這是正常的 /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libcrypto.a(libcrypto-lib-dso_dlfcn.o): in function `dlfcn_globallookup': (.text+0x17): 警告: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: ../snmplib/.libs/libnetsnmp.a(system.o): in function `netsnmp_str_to_gid': /home/gong/rust-work/github/net-snmp/snmplib/system.c:1492: 警告: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the bc version used for linking /usr/bin/ld: /home/gong/rust-work/github/net-snmp/snmplib/system.c:1494: 警告: Using 'endgrent' in statically linked applications requires at runtime the shared librar from the glibc version used for linking /usr/bin/ld: ../snmplib/.libs/libnetsnmp.a(system.o): in function `netsnmp_str_to_uid': /home/gong/rust-work/github/net-snmp/snmplib/system.c:1459: 警告: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the bc version used for linking /usr/bin/ld: /home/gong/rust-work/github/net-snmp/snmplib/system.c:1461: 警告: Using 'endpwent' in statically linked applications requires at runtime the shared librar from the glibc version used for linking /usr/bin/ld: ../snmplib/.libs/libnetsnmp.a(system.o): in function `netsnmp_getaddrinfo': /home/gong/rust-work/github/net-snmp/snmplib/system.c:884: 警告: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: ../snmplib/.libs/libnetsnmp.a(system.o): in function `netsnmp_gethostbyaddr': /home/gong/rust-work/github/net-snmp/snmplib/system.c:1050: 警告: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries frome glibc version used for linking /usr/bin/ld: ../snmplib/.libs/libnetsnmp.a(system.o): in function `netsnmp_gethostbyname': /home/gong/rust-work/github/net-snmp/snmplib/system.c:980: 警告: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from glibc version used for linking
檢查snmpwalk
鏈接
$ ldd snmpwalk
不是動(dòng)態(tài)可執(zhí)行文件
之后也可以把生成的snmpwalk
復(fù)制到另外一臺(tái)古老的linux
上運(yùn)行校驗(yàn),如果機(jī)器上有docker
, 可以執(zhí)行命令docker run -it alpine sh
,把snmpwalk
復(fù)制到容器內(nèi)部執(zhí)行
以上就是net-snmp靜態(tài)編譯鏈接的獲取程序及生成執(zhí)行程序詳解的詳細(xì)內(nèi)容,更多關(guān)于net-snmp靜態(tài)編譯鏈接的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
解析scratch3.0二次開(kāi)發(fā)之scratch-blocks免編譯修改問(wèn)題
大家在使用scratch-blocks編譯時(shí)會(huì)遇到scratch-gui依賴(lài)的scratch-blocks模塊在安裝的時(shí)候編譯會(huì)報(bào)錯(cuò),針對(duì)這個(gè)問(wèn)題我們?cè)撛趺唇鉀Q呢,下面小編給大家?guī)?lái)了scratch3.0二次開(kāi)發(fā)之scratch-blocks免編譯修改方法,感興趣的朋友一起看看吧2021-08-08chatGPT使用及注冊(cè)過(guò)程中常見(jiàn)的一些錯(cuò)誤解決方法(所有報(bào)錯(cuò)匯總)
這篇文章主要介紹了chatGPT注冊(cè)報(bào)錯(cuò)及使用過(guò)程中報(bào)錯(cuò)匯總及解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-02-02Postman配置多環(huán)境請(qǐng)求地址的實(shí)現(xiàn)
本文主要介紹了Postman配置多環(huán)境請(qǐng)求地址的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01判斷Email地址是否正確的幾個(gè)函數(shù)(asp/php/javascript)
今天總結(jié)了幾個(gè)判斷Email地址的函數(shù),和大家分享一下2010-08-08Unity通過(guò)BlendShape實(shí)現(xiàn)面部表情過(guò)渡切換Animation教程
眼睛慢慢瞇成一條線(xiàn)的人都是實(shí)力很強(qiáng)勁的,教你在Unity中通過(guò)BlendShape來(lái)實(shí)現(xiàn)角色面部表情過(guò)渡切換Animation,有需要的朋友可以借鑒參考下2021-09-09在IDEA(2020.2)中配置Git及使用Git的圖文詳解
這篇文章主要介紹了在IDEA(2020.2)中配置Git及使用Git的圖文詳解,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12