平時(shí)遇到的小問(wèn)題總結(jié)

brew

brew使用時(shí)提示error:not writable

liyongdeMacBook-Pro:~ ly$ brew update
Error: /usr/local is not writable. You should change the
ownership and permissions of /usr/local back to your
user account:
sudo chown -R $(whoami) /usr/local

在終端使用sudo chown -R $(whoami) /usr/local回車后輸入電腦密碼即可
```base


#獲取執(zhí)行權(quán)限
chmod 777 ~/.test.sh
chmod 777 絕對(duì)路徑

#編輯文件
sudo nano 文件的絕對(duì)路徑


## Other Linker Flags
解決方法在背景那塊我就提到了,就是在Other Linker Flags里加上所需的參數(shù),用到的參數(shù)一般有以下3個(gè):

-ObjC
-all_load
-force_load
下面來(lái)說(shuō)說(shuō)每個(gè)參數(shù)存在的意義和具體做的事情。

首先是-ObjC,一般這個(gè)參數(shù)足夠解決前面提到的問(wèn)題,蘋果官方說(shuō)明如下:

This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes.

簡(jiǎn)單說(shuō)來(lái),加了這個(gè)參數(shù)后,鏈接器就會(huì)把靜態(tài)庫(kù)中所有的Objective-C類和分類都加載到最后的可執(zhí)行文件中,雖然這樣可能會(huì)因?yàn)榧虞d了很多不必要的文件而導(dǎo)致可執(zhí)行文件變大,但是這個(gè)參數(shù)很好地解決了我們所遇到的問(wèn)題。但是事實(shí)真的是這樣的嗎?

如果-ObjC參數(shù)真的這么有效,那么事情就會(huì)簡(jiǎn)單多了。

Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -allload or -forceload flags.

當(dāng)靜態(tài)庫(kù)中只有分類而沒(méi)有類的時(shí)候,-ObjC參數(shù)就會(huì)失效了。這時(shí)候,就需要使用-all_load或者-force_load了。

-all_load會(huì)讓鏈接器把所有找到的目標(biāo)文件都加載到可執(zhí)行文件中,但是千萬(wàn)不要隨便使用這個(gè)參數(shù)!假如你使用了不止一個(gè)靜態(tài)庫(kù)文件,然后又使用了這個(gè)參數(shù),那么你很有可能會(huì)遇到ld: duplicate symbol錯(cuò)誤,因?yàn)椴煌膸?kù)文件里面可能會(huì)有相同的目標(biāo)文件,所以建議在遇到-ObjC失效的情況下使用-force_load參數(shù)。

-force_load所做的事情跟-all_load其實(shí)是一樣的,但是-force_load需要指定要進(jìn)行全部加載的庫(kù)文件的路徑,這樣的話,你就只是完全加載了一個(gè)庫(kù)文件,不影響其余庫(kù)文件的按需加載。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容