我在寫一個使用gccxml的工具。基本上我解析了由gccxml創建的輸出xml文件。這在Visual Studio的Windows機器上非常有用,除了有一些缺點。這是我的項目的當前狀態:從我的代碼中調用gccxml(Windows)
cmake_gui給了我一個完美編譯的視覺工作室解決方案(x64 Release)。它設置爲在E:\ cmake_builds \ GCCXML \ bin \ Release中創建三個可執行文件。
我自己的C++工具位於不同的VS解決方案文件中。當它應該利用gccxml下面的代碼使用的:
bool Parser::ParseFile(const std::string& _szFileName, std::string& _gccxmlPath,
const std::string& _tempFileLocation,
std::string& _errorStr)
{
bool retVal = true;
printf("Parsing file %s...\n\n", _szFileName.c_str());
/* format _gccxmlPath, adding a final forward slash to the path if required */
char lastChar = _gccxmlPath.at(_gccxmlPath.length()-1);
if(lastChar != '/' && lastChar != '\\')
_gccxmlPath += "/";
/* set up a temporary environment path variable so that the gccxml exe files may locate each other */
char envPath[500];
sprintf_s(envPath, "PATH=%s", _gccxmlPath.c_str());
const char* gccxml_env[] =
{
/* set path to gccxml directory where all exe files from gccxml are located */
envPath,
0
};
/* path & filename of gccxml.exe */
char gccxml_exe[500];
sprintf_s(gccxml_exe, "%sgccxml.exe", _gccxmlPath.c_str());
/* parameter string used to set gccxml output filename */
char fxmlParam[500];
sprintf_s(fxmlParam, "-fxml=\"%s\"", _tempFileLocation.c_str());
/* synthesize argument list for gccxml*/
/* see: http://gccxml.github.io/HTML/Running.html */
/* and: https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Invoking-GCC.html */
const char* gccxml_args[GCCXML_PARAM_LEN];
unsigned int curPos = 0;
/* 1st argument: exe name */
gccxml_args[curPos++] = "gccxml.exe";
/* the source code to be compiled */
gccxml_args[curPos++] = _szFileName.c_str();
/* try to find out which msvc compiler to use */
gccxml_args[curPos++] = "--gccxml-compiler cl";
/* the output xml file */
gccxml_args[curPos++] = fxmlParam;
/* last argument: zero termination */
gccxml_args[curPos++] = 0;
/* call gccxml & compile the source code file */
if(0 != _spawnvpe(P_WAIT, gccxml_exe, gccxml_args, gccxml_env))
{
_errorStr += "GCCXML Compiler Error";
return false;
}
/* now parse the gccxml output file from tempfile ... */
...
...
return retVal;
}
,你可以看到我有建立一個本地環境PATH變量,以確保三個可執行文件都能夠找到對方。
這對我想要做的事很有用。
不幸的是,我不能用這種方法調用gccxml.exe,當我將移動到三個可執行文件到不同的目錄。當然,我提供新的_gccxmlPath字符串,但gccxml返回
"Support item Vc10/Include is not available..."
告訴我它看着我感動的可執行文件的文件夾中。然而,我所有的本地Vc10/Include副本都位於完全不同的地方,我不明白在移動可執行文件之前它是如何找到其中之一的。
似乎可以通過使用參數「patch_dir」調用gccxml_vcconfig.exe並從我的gccxml源文件中提供目錄「gccxml/Source/GCC_XML/VcInstall」來解決此問題。然而,我不能用這種方式使用任何spawn *命令來解決我的問題。 如果我做的gccxml_vcconfig.exe運行得很好,但在此之後,我試圖調用gccxml.exe,事實證明,它仍然像以前一樣在目錄中查找。
那麼gccxml_vcconfig.exe可能不是我正在尋找的?
我試圖找到一種方法來爲不想在他們的機器上重新編譯gccxml的用戶提供我的工具,所以我想分發三維二進制文件(還有其他需要的)。