- 寫cmakelist
- 用vs2017打開
- vs2017->工具->選項(xiàng)->跨平臺(tái):添加一個(gè)遠(yuǎn)程linux連接策精。
- 修改cmakesetting.json
{
"configurations": [
{
"name": "Linux-Debug", //復(fù)制到遠(yuǎn)程工程文件夾目錄名稱儡嘶,可以自定義愧薛。
"generator": "Unix Makefiles", //使cmake生成makefile
//"remoteMachineName": "${defaultRemoteMachineName}",
"remoteMachineName": "192.168.30.62", //剛剛添加的linux服務(wù)器地址
"configurationType": "Debug",
// "remoteCMakeListsRoot": "/var/tmp/src/${workspaceHash}/${name}",
"remoteCMakeListsRoot": "/home/user1/${name}",//copy到遠(yuǎn)程的這一路徑戒洼,對(duì)于連接的用戶抖棘,需要有這一路徑的操作權(quán)限,如果沒有權(quán)限偏塞,將會(huì)導(dǎo)致vs在遠(yuǎn)程創(chuàng)建此路徑文件夾失敗唱蒸。
"cmakeExecutable": "/usr/local/bin/cmake",//遠(yuǎn)程cmake路徑
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",//默認(rèn)就好,也可以設(shè)置成本地工程所在的build目錄
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",//同上
"remoteBuildRoot": "/home/user1/${name}/build",//遠(yuǎn)程執(zhí)行cmake構(gòu)建的路徑灸叼,建議就按我這個(gè)寫神汹,指定到遠(yuǎn)程工程目錄下的build目錄。
"remoteInstallRoot": "/home/user1/${name}/install",//遠(yuǎn)程cmake安裝路徑
"remoteCopySources": true,
"remoteCopySourcesOutputVerbosity": "Normal",
"remoteCopySourcesConcurrentCopies": "10",
"remoteCopySourcesMethod": "sftp",//此處建議使用sftp古今,另外一個(gè)總是出現(xiàn)字符編碼不兼容的問題屁魏。
"remoteCopySourcesExclusionList": [ //忽略以下目錄不copy到遠(yuǎn)程,可以將于編譯無關(guān)的目錄都添加上捉腥。
".vs",
".git"
],
"rsyncCommandArgs": "-t --delete --delete-excluded",
"remoteCopyBuildOutput": false,
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [
"linux_x64"
]
}
]
}
- 連接遠(yuǎn)程linux氓拼,生成〉值可能會(huì)出現(xiàn)以下錯(cuò)誤:
- 錯(cuò)誤1:提示調(diào)用遠(yuǎn)程cmake失敗
(此處調(diào)用的是/usr/local/bin/cmake桃漾,看一下是不是cmake裝在了/usr/bin/目錄下,如果是拟逮,可以為cmake創(chuàng)建一個(gè)軟連接)
ln -s /usr/local/bin/cmake /usr/bin
或者修改 CMakeSettings.json中的cmakeExecutable的值:改成遠(yuǎn)程linux cmake的目錄
- 錯(cuò)誤2:
Input string was not in a correct format.(輸入字符串格式錯(cuò)誤)
如果使用的不是bash撬统,修改為bash,一般是因?yàn)槭褂玫氖莦sh導(dǎo)致敦迄。
chsh -s /bin/bash //修改登錄時(shí)使用bash
參考:https://github.com/Microsoft/VSLinux/issues/196 arrowd的回答恋追。
錯(cuò)誤3:
vs2017 點(diǎn)擊運(yùn)行,提示 could not load cache
解決方法:
1.vs2017->cmake->緩存->生成罚屋】啻眩或者到遠(yuǎn)程服務(wù)器編譯目錄手動(dòng)cmake一下就會(huì)生成cmakecache.txt啦錯(cuò)誤4:
vs在提示往服務(wù)器復(fù)制文件過程中,復(fù)制失敗脾猛。
解決方法:
- Google了很多撕彤,沒有找到根本的原因∶退可以嘗試將本地的編譯過程文件目錄都刪除掉喉刘,或者為
cmakesetting.json
的remoteCopySourcesExclusionList
添加不需要復(fù)制到遠(yuǎn)程的目錄瞧柔,盡量讓vs只復(fù)制代碼文件。然后多次嘗試生成睦裳、多次嘗試。
-錯(cuò)誤5:
如果提示遠(yuǎn)程cmakechache.txt文件有問題撼唾,直接到遠(yuǎn)程服務(wù)器編譯目錄下把這個(gè)文件刪除廉邑。