如何修复Code::Blocks向导以查找GTK+;3.0而不是2.0?
自从我开始用C编程以来,在尝试了每一个C编译器之后,我一直在使用Code::Blocks 在windows下,我发现Code::Blocks最容易使用,因为我不必花一整年的时间学习如何使用该程序,就可以开始在it XD中编写“hello world”应用程序 无论如何,我安装了GTK+3.0,设置了环境变量,并按照安装教程的要求运行cmd提示符命令。。。。我甚至在cmd提示符下运行了gtk演示文件……当我运行Code::Blocks 13.10 gtk+向导时,它一直告诉我gtk+似乎已安装,但它找不到gtk.h。在做了一些挖掘之后,我意识到它在寻找gtk-2.0文件夹,而不是gtk-3.0文件夹如何修复Code::Blocks向导以查找GTK+;3.0而不是2.0?,c,codeblocks,gtk3,C,Codeblocks,Gtk3,自从我开始用C编程以来,在尝试了每一个C编译器之后,我一直在使用Code::Blocks 在windows下,我发现Code::Blocks最容易使用,因为我不必花一整年的时间学习如何使用该程序,就可以开始在it XD中编写“hello world”应用程序 无论如何,我安装了GTK+3.0,设置了环境变量,并按照安装教程的要求运行cmd提示符命令。。。。我甚至在cmd提示符下运行了gtk演示文件……当我运行Code::Blocks 13.10 gtk+向导时,它一直告诉我gtk+似乎已安装,但
另一个论坛上的某个人似乎通过将向导脚本中的2.0更改为3.0来克服这一部分,但声称一旦他尝试编译它,它会给他带来更多错误。好了,各位,我找到了答案…..我转到命令控制台,运行此命令以获取所有版本信息:pkg config--cflags gtk+-3.0 通过这样做,我得到了以下信息:-mms位域-IC:/GTK3/include/gtk-3.0-IC:/GTK3/include/CAROI-IC:/GTK3/include/pango-1.0-IC:/GTK3/atk-1.0-IC:/GTK3/include/CAROI-IC:/GTK3/include/pixman-1-IC:/GTK3/include-IC:/GTK3/GTK3/include-IC/GTK3/include-IC:/GTK3/libpng15-IC:/GTK3/include/gdk-pixbuf-2-IC:/GTK3/include/libpng15-IC:/GTK3/include/glib-2.0-IC:/GTK3/lib/glib-2.0/include 我进入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;
}
////////////////////////////////////////////////////////////////////////////////
//
//GTK项目向导
//
////////////////////////////////////////////////////////////////////////////////
//全球的
GtkPathDefault好了,各位,我找到了答案……我去了命令控制台,运行这个命令来获取所有版本的信息:pkg config--cflags gtk+-3.0
通过这样做,我得到了以下信息:-mms位域-IC:/GTK3/include/gtk-3.0-IC:/GTK3/include/CAROI-IC:/GTK3/include/pango-1.0-IC:/GTK3/atk-1.0-IC:/GTK3/include/CAROI-IC:/GTK3/include/pixman-1-IC:/GTK3/include-IC:/GTK3/GTK3/include-IC/GTK3/include-IC:/GTK3/libpng15-IC:/GTK3/include/gdk-pixbuf-2-IC:/GTK3/include/libpng15-IC:/GTK3/include/glib-2.0-IC:/GTK3/lib/glib-2.0/include
我进入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;
}
////////////////////////////////////////////////////////////////////////////////
//
//GTK项目向导
//
////////////////////////////////////////////////////////////////////////////////
//全球的
GtkPathDefault这些详细信息可能不适用于除17.12以外的任何版本的CODE::BLOCKS
我在Ubuntu 16.04上的代码::Blocks 17.12也有同样的问题
根据上面的答案,解决方案(对我来说)是修改GTK向导脚本,但这与描述的略有不同,可能是因为不同的Code::Blocks版本
代码::块->新建->项目->右键单击“GTK+项目”->选择“编辑此脚本”
代码::块现在将在编辑器窗格中显示脚本。但是这个脚本被锁定了。它也不会保存在任何地方
保存文件
代码::块->文件->保存
该文件将作为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”
开始代码::块并创建一个新项目。现在应该可以编译了
注意:以前创建的GTK3项目将不会编译
注意:代码::Blocks New->Project->GTK+向导图标现在将显示为红色。这表示GTK+项目向导脚本已被修改 这些详细信息可能不适用于除17.12以外的任何版本的CODE::BLOCKS
我在Ubuntu 16.04上的代码::Blocks 17.12也有同样的问题
根据上面的答案,解决方案(对我来说)是修改GTK向导脚本,但这与描述的略有不同,可能是因为不同的Code::Blocks版本
代码::块->新建->项目->右键单击“GTK+项目”->选择“编辑此脚本”
代码::块现在将在编辑器窗格中显示脚本。但是这个脚本被锁定了。它也不会保存在任何地方
保存文件
代码::块->文件->保存
该文件将作为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”
开始代码::块并创建一个新项目。现在应该可以编译了
注意:以前创建的GTK3项目将不会编译
注意:代码::Blocks New->Project->GTK+向导图标现在将显示为红色。这表示GTK+项目向导脚本已被修改 太好了。为我工作是完美的。为我工作