[英]How to setup GTK+ to develop with Code::Blocks on Ubuntu Linux
[英]How to fix the Code::Blocks wizard to look for GTK+ 3.0 and not 2.0?
自從我開始使用C語言進行編程以來,我一直在使用Code :: Blocks,在Windows下嘗試存在的每個C編譯器之后,我發現Code :: Blocks最容易使用,因為我不必花整整一年的時間學習如何在開始使用XD編寫“ Hello World”應用程序之前,請先使用該程序。
無論如何,我安裝了GTK + 3.0並設置了環境變量,並按照設置教程的要求運行了cmd提示命令...。我什至從cmd提示中運行了gtk-demo文件。 Code :: Blocks 13.10 gtk +向導一直告訴我GTK +似乎已安裝,但在進行一些挖掘后找不到gtk.h,我意識到它正在尋找gtk-2.0文件夾而不是gtk-3.0文件夾。 ..
另一個論壇上的某個人似乎已通過將向導腳本中的2.0更改為3.0來超越了這一部分,但聲稱一旦他嘗試編譯它,它就會給他帶來更多錯誤。
好的,我知道了.....我去了命令控制台並運行了該命令以獲取所有版本信息:pkg-config --cflags gtk + -3.0
通過這樣做,我得到了以下信息:-mms-bitfields -IC:/GTK3/include/gtk-3.0 -IC:/ GTK3 / include / cairo -IC:/GTK3/include/pango-1.0 -IC:/ GTK3 / include / atk-1.0 -IC:/ GTK3 / include / cairo -IC:/ GTK3 / include / pixman-1 -IC:/ GTK3 / include -IC:/ GTK3 / include / freetype2 -IC:/ GTK3 / include -IC :/ GTK3 / include / libpng15 -IC:/GTK3/include/gdk-pixbuf-2.0 -IC:/ GTK3 / include / libpng15 -IC:/GTK3/include/glib-2.0 -IC:/ GTK3 / lib / glib- 2.0 /包括
我進入Code :: Blocks,然后轉到File-> New-> Project:然后我右鍵單擊GTK +項目圖標並選擇“編輯此腳本”,我遍歷了文件並更改了文件以匹配上面的版本信息
////////////////////////////////////////////////////////////////////////////////
//
// GTK project wizard
//
////////////////////////////////////////////////////////////////////////////////
// globals
GtkPathDefault <- _T("$(#gtk)");
GtkPathDefaultInc <- _T("$(#gtk.include)");
GtkPathDefaultLib <- _T("$(#gtk.lib)");
GtkPath <- _T("");
// GtkVersion <- 1; // 0 - GTK+, 1 - GTK+-2.0
function BeginWizard()
{
local intro_msg = _T("Welcome to the new GTK project wizard!\n" +
"This wizard will guide you to create a new GTK project\n" +
"using the GTK cross-platform GUI toolkit\n\n" +
"When you're ready to proceed, please click \"Next\"...");
local gtkpath_msg = _T("Please select the location of GTK on your computer.\n" +
"This is the top-level folder where GTK was installed.\n" +
"To help you, this folder must contain the subfolders\n" +
"\"include\" and \"lib\".");
Wizard.AddInfoPage(_T("GtkIntro"), intro_msg);
Wizard.AddProjectPathPage();
if (PLATFORM == PLATFORM_MSW)
{
Wizard.AddGenericSelectPathPage(_T("GtkPath"), gtkpath_msg, _T("GTK's location:"), GtkPathDefault);
}
/*else
{
Wizard.AddGenericSingleChoiceListPage(_T("GtkVersionPage"), _T("Please select the GTK+ version you want to use."), _T("GTK+ 1.x;GTK+ 2.x"), GtkVersion); // select GTK+ version
}*/
Wizard.AddCompilerPage(_T(""), _T("gcc*"), true, true);
}
////////////////////////////////////////////////////////////////////////////////
// Gtk's path page
////////////////////////////////////////////////////////////////////////////////
function OnLeave_GtkPath(fwd)
{
if (fwd)
{
local dir = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
local dir_nomacro = VerifyDirectory(dir);
if (dir_nomacro.IsEmpty())
return false;
// verify include dependencies
local dir_nomacro_inc = GetCompilerIncludeDir(dir, GtkPathDefault, GtkPathDefaultInc);
if (dir_nomacro_inc.IsEmpty())
return false;
if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-3.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))
return false;
// verify library dependencies
local dir_nomacro_lib = GetCompilerLibDir(dir, GtkPathDefault, GtkPathDefaultLib);
if (dir_nomacro_lib.IsEmpty())
return false;
if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-win32-3.0"), _T("GTK's")))
return false;
GtkPath = dir; // Remember the original selection.
local is_macro = _T("");
// try to resolve the include directory as macro
is_macro = GetCompilerIncludeMacro(dir, GtkPathDefault, GtkPathDefaultInc);
if (is_macro.IsEmpty())
{
// not possible -> use the real inc path we had computed instead
GtkPathDefaultInc = dir_nomacro_inc;
}
// try to resolve the library directory as macro
is_macro = GetCompilerLibMacro(dir, GtkPathDefault, GtkPathDefaultLib);
if (is_macro.IsEmpty())
{
// not possible -> use the real lib path we had computed instead
GtkPathDefaultLib = dir_nomacro_lib;
}
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Gtk's version page (For *nix users)
////////////////////////////////////////////////////////////////////////////////
function OnLeave_GtkVersionPage(fwd)
{
if (fwd)
{
GtkVersion = Wizard.GetListboxSelection(_T("GenericChoiceList"));
}
return true;
}
// return the files this project contains
function GetFilesDir()
{
return _T("gtk/files");
}
// setup the already created project
function SetupProject(project)
{
if (PLATFORM == PLATFORM_MSW)
{
project.AddIncludeDir(GtkPathDefaultInc);
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-3.0"));
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("cairo"));
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk"));
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("glib-2.0"));
// Notice GtkPathDefault*Lib* at some positions. This is correct as of 2.8.20
project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("glib-2.0") + wxFILE_SEP_PATH + _T("include"));
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("pango-1.0"));
project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-3.0") + wxFILE_SEP_PATH + _T("include"));
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("atk-1.0"));
if ( IO.DirectoryExists(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk-pixbuf-2.0")) )
project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk-pixbuf- 2.0"));
project.AddLibDir(GtkPathDefaultLib);
// add link libraries
project.AddLinkLib(_T("gtk-win32-3.0"));
project.AddLinkLib(_T("gobject-2.0"));
project.AddLinkLib(_T("glib-2.0"));
// Notice: there are more libs required as the app gets more complex, e.g.:
// pangocairo-1.0.lib, pangocairo-1.0.lib, libatk-1.0.dll.a,
// gdk_pixbuf-2.0.lib, gdk-win32-2.0.lib, pango-1.0.lib,
// gmodule-2.0.lib, gthread-2.0.lib, cairo.lib,
// pangoft2-1.0.lib (...)
project.AddCompilerOption(_T("-mms-bitfields"));
}
else
{
/*if (GtkVersion == 1)
{*/
project.AddCompilerOption(_T("`pkg-config gtk+-3.0 --cflags`"));
project.AddLinkerOption(_T("`pkg-config gtk+-3.0 --libs`"));
/*}
else
{
project.AddCompilerOption(_T("`pkg-config gtk+ --cflags`"));
project.AddLinkerOption(_T("`pkg-config gtk+ --libs`"));
}*/
}
// enable compiler warnings (project-wide)
WarningsOn(project, Wizard.GetCompilerID());
// Debug
local target = project.GetBuildTarget(Wizard.GetDebugName());
if (!IsNull(target))
{
target.SetTargetType(ttConsoleOnly); // ttConsoleOnly: console for debugging
target.SetOutputFilename(Wizard.GetDebugOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
// enable generation of debugging symbols for target
DebugSymbolsOn(target, Wizard.GetCompilerID());
}
// Release
target = project.GetBuildTarget(Wizard.GetReleaseName());
if (!IsNull(target))
{
target.SetTargetType(ttExecutable); // ttExecutable: no console
target.SetOutputFilename(Wizard.GetReleaseOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
// enable optimizations for target
OptimizationsOn(target, Wizard.GetCompilerID());
}
return true;
}
如果要設置Code :: Blocks,以便它不會在GTK + GUI后面打開win32控制台窗口,請轉到Project-> Properties-> Build target,然后在“ Selected build target options”下選擇Type:下拉列表並選擇GUI應用程序,可能會選擇“控制台應用程序”
編輯:找出來,檢查完上面的腳本后,我意識到您不必經歷所有麻煩即可刪除控制台,您所需要做的就是選擇“運行”右側的下拉菜單。工具欄,並將其從“調試”切換到“發布XD”
這些詳細信息可能不適用於17.12以外的任何版本的Code :: Blocks
我在Ubuntu 16.04上的Code :: Blocks 17.12有相同的問題
根據上面的答案,解決方案(對我而言)是修改GTK向導腳本,但這與所描述的略有不同,可能是因為Code :: Blocks版本不同。
代碼::塊->新建->項目->右鍵單擊“ GTK +項目”->選擇“編輯此腳本”
Code :: Blocks現在將在編輯器窗格中顯示一個腳本。 但是此腳本已鎖定。 它也不會保存在任何地方。
保存文件Code :: Blocks-> File-> Save
該文件將作為Wizard.script保存到〜/ .local / share / codeblocks / templates / wizard / gtk。
在Code :: Blocks中關閉此文件(在編輯器窗格選項卡中單擊“ x”)
使用其他一些編輯器(vi(m),Geany等)打開文件
文件底部附近是線條...
project.AddCompilerOption(_T("`pkg-config gtk+-2.0 --cflags`"));
project.AddLinkerOption(_T("`pkg-config gtk+-2.0 --libs`"));
注釋掉這些並添加兩個新行或按如下所示修改這些行
project.AddCompilerOption(_T("`pkg-config gtk+-3.0 --cflags`"));
project.AddLinkerOption(_T("`pkg-config gtk+-3.0 --libs`"));
注意兩行中的'gtk + -2.0'已更改為'gtk + -3.0'
啟動代碼::: Blocks並創建一個新項目。 現在應該可以編譯了。
注意:先前創建的GTK3項目將無法編譯。
注意:Code :: Blocks New-> Project-> GTK + Wizard圖標現在將以紅色顯示。 這表明GTK +項目向導腳本已被修改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.