問題描述
我正在嘗試將我為課堂編寫的舊程序從 Ubuntu 中的 KDev 移植到 Windows Visual Studio 2008,使用 Cygwin 作為個人學習練習.我將包含路徑配置為包含 C:cygwinusrinclude
但它沒有正確讀取 .h 文件.
I'm trying to port an old program I wrote for class from KDev in Ubuntu to Windows Visual Studio 2008 using Cygwin as a personal learning exercise. I have the include path configured to include C:cygwinusrinclude
but it doesn't read the .h files properly.
也就是說,我很好奇如何在使用 Cygwin 的 Visual Studio 環境中使用 unix sockets.h
功能.有沒有人做過這個工作或有更簡單的方法來做這件事?
Namely I'm curious as to how one would go about using unix sockets.h
functionality in a Visual Studio environment using Cygwin. Has anybody ever got this working or have an easier way to go about doing this?
推薦答案
有幾種方法可以解決這個問題,具體取決于您的確切目標.最簡單的方法可能只是創建一個 Visual Studiomakefile"項目,該項目觸發自定義構建命令來運行您構建的 makefile.但這使您無法享受 Visual Studio 作為 IDE 的許多好處,所以我猜這并不是您真正想要的.
There are several ways to go about this that could be made to work, depending upon your exact goals. The simplest way is probably just to create a Visual Studio "makefile" project that fires off a custom build command to run a makefile you've built. But that keeps you away from a lot of the nice benefits of Visual Studio as an IDE, so I'm guessing that's not really what you're after.
如果您想要一個更完全集成的解決方案,您需要做兩件事.首先,您將需要更改所有包含/庫路徑,以避免使用 Microsoft 路徑,轉而使用 Cygwin 路徑.您可以通過從菜單中選擇工具->選項",然后從出現的窗口左側的樹中選擇項目和解決方案->VC++ 目錄"來完成此操作.您可以選擇更改可執行文件、標頭、庫等的搜索目錄.對于您要執行的操作,我建議刪除所有內容并僅添加 cygwin 目錄.
If you want a more fully integrated solution, you're going to need to do two things. First of all, you're going to need to change out all of your include/library paths to avoid the Microsoft ones and go after the Cygwin ones instead. You can do this by selecting "Tools->Options" from the menu, then choosing "Projects and Solutions->VC++ Directories" from the tree on the left hand side of the window that comes up. You'll have options to change the search directories for executables, headers, libraries, etc. For what you're trying to do, I'd suggest removing everything and adding in just the cygwin directories.
其次,您必須告訴 Visual Studio 使用 gcc/g++ 編譯器.這有點棘手.VS 支持自定義文件類型的自定義構建規則……但它似乎為 Microsoft 編譯器硬連接了 C++.除了使用您自己的自定義文件擴展名之外,我真的不知道有什么好的方法可以解決這個問題.您可以嘗試 .c(C 文件)和 .cc(C++ 文件)的標準 unix 擴展名,但我懷疑 Visual Studio 會自動選擇這些.你可能不得不選擇完全陌生的東西.
Second, you'll have to tell Visual Studio to use the gcc/g++ compiler. This is a bit trickier. VS supports custom build rules for custom file types... but it seems to have C++ hardwired in for the Microsoft compiler. I don't really know a great way around that except to use your own custom file extension. You can try the standard unix extensions of .c (C files) and .cc (C++ files), but I suspect Visual Studio will automatically pick up on those. You may have to go with something totally foreign.
如果您在解決方案資源管理器中右鍵單擊您的項目并選擇自定義構建規則",您將獲得一個界面,讓您可以為您選擇的文件擴展名創建自定義構建規則.界面相對簡單.
If you right click on your project in the Solution Explorer and select "Custom Build Rules" you'll be given an interface that will let you create your custom build rules for the file extension you've chosen. The interface is relatively straightforward from there.
這可能無法完全滿足您的需求,但它可能與您使用 Visual Studio 獲得的效果差不多.
This might not get you exactly what you wanted, but it's probably about as close as you're going to get with Visual Studio.
這篇關于Visual Studio 中的 Cygwin的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!