I am trying to use GTK3 and WebKitGTK. I am successful at running the following code :
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
#include <JavaScriptCore/JavaScript.h>
using namespace std;
static void destroyWindowCb(GtkWidget* widget, GtkWidget* window);
static gboolean closeWebViewCb(WebKitWebView* webView, GtkWidget* window);
int main(int argc, char* argv[])
{
// Initialize GTK+
gtk_init(&argc, &argv);
// Create an 800x600 window that will contain the browser instance
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
// Create a browser instance
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
// Put the browser area into the main window
gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView));
// Set up callbacks so that if either the main window or the browser instance is
// closed, the program will exit
g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
g_signal_connect(webView, "close", G_CALLBACK(closeWebViewCb), main_window);
// Load a web page into the browser instance
webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/");
// Make sure that when the browser area becomes visible, it will get mouse
// and keyboard events
gtk_widget_grab_focus(GTK_WIDGET(webView));
// Make sure the main window and all its contents are visible
gtk_widget_show_all(main_window);
// Run the main GTK+ event loop
gtk_main();
return 0;
}
static void
destroyWindowCb(GtkWidget* widget, GtkWidget* window)
{
gtk_main_quit();
}
static gboolean
closeWebViewCb(WebKitWebView* webView, GtkWidget* window)
{
gtk_widget_destroy(window);
return TRUE;
}
And the following cmake list :
cmake_minimum_required(VERSION 3.3)
project(HttpsMock)
# Use the package PkgConfig to detect GTK+ headers/library files
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(WEBKIT REQUIRED webkitgtk-3.0)
# Setup CMake to use GTK+, tell the compiler where to look for headers
include_directories(${GTK3_INCLUDE_DIRS})
include_directories(${WEBKIT_INCLUDE_DIRS})
# and to the linker where to look for libraries
link_directories(${GTK3_LIBRARY_DIRS})
link_directories(${WEBKIT_LIBRARY_DIRS})
# Add other flags to the compiler
add_definitions(${GTK3_CFLAGS_OTHER})
add_definitions(${WEBKIT_CFLAGS_OTHER})
# Flags and source
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -v")
set(SOURCE_FILES main.cpp)
add_executable(HttpsMock ${SOURCE_FILES})
# Linking
target_link_libraries(HttpsMock ${GTK3_LIBRARIES})
target_link_libraries(HttpsMock ${WEBKIT_LIBRARIES})
But as soon as I try to use another method like :
WebKitURIRequest *request = webkit_uri_request_new("http://www.webkitgtk.org/");
The program doesn't want to link anymore. It's really weird. Here's a sample of the error :
[100%] Linking CXX executable HttpsMock
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -o HttpsMock -L/opt/local/lib -search_paths_first -headerpad_max_install_names CMakeFiles/HttpsMock.dir/main.cpp.o -lwebkitgtk-3.0 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpangoft2-1.0 -lpango-1.0 -lm -lfontconfig -lfreetype -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lsoup-2.4 -lgio-2.0 -lgobject-2.0 -ljavascriptcoregtk-3.0 -lglib-2.0 -lintl -rpath /opt/local/lib -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_webkit_uri_request_new", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
I really have no clue of what is going on. Could someone please enlighten me?
Thanks
The problem is that I was using
pkg_check_modules(WEBKIT REQUIRED webkitgtk-3.0)
instead of
pkg_check_modules(WEBKIT REQUIRED webkit2gtk-3.0)
Related
I'm trying to compile a simple SDL program using Mingw w64. Here is my code:
test.c
#include "SDL2/SDL.h"
#include <stdio.h>
int main( int argc, char* args[] )
{
SDL_Window *window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("SDL2 Window", 100, 100, 640, 480, 0);
if(window==NULL)
{
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
and here is the command I'm using to compile the program:
g++ -o text.exe test.c -I./include -L./lib -lmingw32 -lSDL2main -lSDL2
but when I compile the program, I get hundreds of linking errors that look like this:
./lib/libSDL2.a(SDL_wasapi_win32.o): In function `WASAPI_PlatformInit':
/Users/valve/release/SDL/SDL2-2.0.22-source/foo-x64/../src/audio/wasapi/SDL_wasapi_win32.c:255: undefined reference to `__imp_CoCreateInstance'
I downloaded the library from the second link down in the windows development libraries section on the official SDL website, and took the libraries from the following directory:
SDL2-2.0.22\x86_64-w64-mingw32\lib
The contents of ./lib are:
libSDL2main.a
libSDL.a
What is the problem and how can I fix it?
You have two options, depending on your intent:
If you want to link SDL2 dynamically (this should be your default course of action), you need to add libSDL2.dll.a to your library directory. Then libSDL2.a will be ignored and can be removed. It should just work, no other changes are needed.
If you want to statically link SDL2, you need more linker flags. The exact flags are listed in sdl2.pc in the Libs.private section.
As of SDL 2.0.22, those are: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid.
Those should be added to the right of -lmingw32 -lSDL2main -lSDL2.
You also might want to add -static to statically link everything, including the standard library. (What's the point of statically linking SDL2, when your program still needs the DLLs of the standard library to work?) It also makes the linker prefer libSDL2.a to libSDL2.dll.a if both are available, meaning you don't need to worry what's in your library directory.
I have visited all the other questions but from what I see none are my issue.
Running OS X El Capitan 10.11.6 on MacBook Pro 16GB memory Intel Core I7
I have ran brew doctor as well but don't see any issues that would cause this issue. Below is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.0.0)
project(WebClient VERSION 0.0.0)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPLIER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPLIER_SUPPORTS_CXX0X)
if(COMPLIER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support.
Please use a different C++ compiler.")
endif()
FIND_PACKAGE( Boost 1.62 COMPONENTS program_options REQUIRED )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
set(OPT_CPPFLAGS "-I/usr/local/opt/openssl/include -I/usr/local/opt/libiconv/include")
set(OPT_LDFLAGS "-v -lcpprest -lboost_system -L/usr/local/opt/openssl/lib -L/usr/local/opt/libiconv/lib -lcrypto -lssl")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPT_CPPFLAGS} -v -g -O3 -fno-common -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPT_LDFLAGS}")
add_executable(anyExecutable webclient.cpp)
TARGET_LINK_LIBRARIES( anyExecutable ${Boost_LIBRARIES} )
include(CPack)
I used brew to install cpprestsdk/2.8.0 which also includes boost/1.62.0 and openssl/1.0.2j and libiconv/1.14. My code is from a tutorial on wiki cpprestsdk.
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <atomic>
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
int main(int argc, char* argv[]) {
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream( U("results.xml") ).then(
[=](ostream outFile) {
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.dictionaryapi.com/api/v1/references/"));
// Build request URI and start the request.
uri_builder builder(U("thesaurus/xml/"));
builder.append_path(U("ranking"),true);
builder.append_query(U("?key"), U("--------------------"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then( [=](http_response response ) {
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then( [=](size_t ) {
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try {
requestTask.wait();
} catch (const std::exception &e) {
printf("Error exception:%s\n", e.what());
}//try-catch BLOCK
return 0;
}//Main
To save some space only printing some the errors they all the same in can't be found:
[vscode] Executing cmake command: cmake --build /Users/gumpy/git-repos/webapi/build --target all --config Debug -- -j 10
[ 50%] Building CXX object CMakeFiles/anyExecutable.dir/webclient.cpp.o
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name webclient.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 274.1 -v -dwarf-column-info -debug-info-kind=standalone -dwarf-version=2 -debugger-tuning=lldb -coverage-file /Users/gumpy/git-repos/webapi/build/CMakeFiles/anyExecutable.dir/webclient.cpp.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -I /usr/local/include -I /usr/local/opt/openssl/include -I /usr/local/opt/libiconv/include -stdlib=libc++ -O3 -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /Users/gumpy/git-repos/webapi/build -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o CMakeFiles/anyExecutable.dir/webclient.cpp.o -x c++ /Users/gumpy/git-repos/webapi/webclient.cpp
clang -cc1 version 8.0.0 (clang-800.0.38) default target x86_64-apple-darwin15.6.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/usr/local/opt/openssl/include
/usr/local/opt/libiconv/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
[100%] Linking CXX executable anyExecutable
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o anyExecutable -L/usr/local/opt/openssl/lib -L/usr/local/opt/libiconv/lib -search_paths_first -headerpad_max_install_names -lcpprest -lboost_system -lcrypto -lssl CMakeFiles/anyExecutable.dir/webclient.cpp.o /usr/local/lib/libboost_program_options-mt.dylib -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"boost::this_thread::interruption_point()", referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in webclient.cpp.o
boost::condition_variable::do_wait_until(boost::unique_lock<boost::mutex>&, timespec const&) in webclient.cpp.o
"boost::chrono::steady_clock::now()", referenced from:
pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
"boost::chrono::system_clock::now()", referenced from:
pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
"boost::detail::get_current_thread_data()", referenced from:
boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*, _opaque_pthread_cond_t*) in webclient.cpp.o
ld: symbol(s) not found for architecture x86_64
The missing symbol names was due to a missing library. The necessary CPPFLAGS and LDFLAGS are:
CPPFLAGS = -stdlib=libc++
LDFLAGS = -lcpprest -lboost_system -lboost_thread-mt -lboost_chrono-mt -lssl -lcrypto
Thanks so much for everyone's help.
Original Question:
"web::uri_builder::append_path(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
std::__1::__function::__func<main::$_0, std::__1::allocator<main::$_0>, pplx::task<web::http::http_response> (Concurrency::streams::basic_ostream<unsigned char>)>::operator()(Concurrency::streams::basic_ostream<unsigned char>&&) in webclient.cpp.o
"web::uri_builder::append_query(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
web::uri_builder& web::uri_builder::append_query<char [37]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [37], bool) in webclient.cpp.o
"web::uri_builder::to_string()", referenced from:
std::__1::__function::__func<main::$_0, std::__1::allocator<main::$_0>, pplx::task<web::http::http_response> (Concurrency::streams::basic_ostream<unsigned char>)>::operator()(Concurrency::streams::basic_ostream<unsigned char>&&) in webclient.cpp.o
"web::uri::encode_impl(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<bool (int)> const&)", referenced from:
web::uri_builder& web::uri_builder::append_query<char [37]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [37], bool) in webclient.cpp.o
...
The ::__1 is LLVM's anonymous namespace. What you see above is a symptom of mixing and matching runtimes. I.e., inconsistent use of -stdlib=XXX.
You need to build everything with GNU's gear and -stlib=libstdc++; or you need to build everything with LLVM's gear and -stdlib=libc++.
What I found works best to avoid user problems and questions is to always use LLVM's gear on OS X and iOS. I.e., always use -stdlib=libc++.
Updated Question:
Undefined symbols for architecture x86_64:
"boost::this_thread::interruption_point()", referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in webclient.cpp.o
boost::condition_variable::do_wait_until(boost::unique_lock<boost::mutex>&, timespec const&) in webclient.cpp.o
"boost::chrono::steady_clock::now()", referenced from:
pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
"boost::chrono::system_clock::now()", referenced from:
pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
"boost::detail::get_current_thread_data()", referenced from:
boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*, _opaque_pthread_cond_t*) in webclient.cpp.o
ld: symbol(s) not found for architecture x86_64
For the updated question, see Using and building the library in the Boost user guide. You have to build Boost with threading support (does Brew do that?), and you have to link to the Boost threading library (is CMake doing that?).
I don't use Boost or CMake, so I can't take you any further. Sorry about that.
set(OPT_CPPFLAGS "-I/usr/local/opt/openssl/include -I/usr/local/opt/libiconv/include")
I'm no CMake expert, but this could be problematic, too. CPPFLAGS is the flags for the C preprocessor. They may or may not be added to the CFLAGS and CXXFLAGS.
You should definitely call-out the same flags for CFLAGS and CXXFLAGS just in case. If this were an Autotools project, then I would change the should to a must. But like I said, I'm no CMake expert by any strecth of the imagination.
And one final note... You can't use CMake to build OpenSSL. You have to configure an build it yourself. Once installed, you can reference the installed OpenSSL in a find-openssl.cmake type fashion.
The reasons are not readily apprent... OpenSSL's Configure script sets up some important settings that are used later in the build process. The two most important files for the settings are <opensslconf.h> and <bn.h>.
You can also get an impressive speed improvement (2x to 4x) for Diffie-Hellman and Elliptic Curves on Intel-based x86_64 machines by Configureing with enable-ec_nistp_64_gcc_128.
It looks like this may be the same issue you have, with the answer being link against -lcrypto.
Edit: Your problem is that you're trying to build a program that needs to be linked against other "libraries" - that is, other pieces of code that are usually pre-compiled - that are somewhere on your system, and which define "symbols," which is basically another way of saying variables or function names.
You let the compiler know which libraries you need by including arguments to the compile command that signify what you need to be linked with - in this case, your first few issues went away because you linked with -lcrypto, and from then on your code was able to find the 'symbols' - that is, variables and function names - that were previously 'undefined.'
For the rest of your issues, where you added 'lcrypto,' try using the arguments from this wiki on building cpprestsdk on Linux. The flags appear to be:
-lboost_system -lssl -lcpprest -lboost_chrono
Last, but not least, have you follow the instructions for building this software on mac OSX on their site? It might save you a lot of pain! :)
Edit: added a few more.
I'm trying to compile the following
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
return 0;
}
just to verify that my GLFW installation is working. I use the terminal with
clang++ -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -I/opt/local/include/ test.c
but I receive a linker error for the glfwInit function:
Undefined symbols for architecture x86_64:
"_glfwInit", referenced from:
_main in test-d8c21e.o
ld: symbol(s) not found for architecture x86_64
I have installed glfw with sudo port install glfw and followed every possible tutorial I've found. I can verify that the libglfw.dylib file can be found at /opt/local/lib/ as (I think) it should.
Any suggestions?
You need to link with GLFW[3] as well, e.g., add:
-L/opt/local/lib -lglfw3
If you have the pkgconfig port installed, you can also take advantage of that with:
clang `pkg-config glfw3 --cflags` test.c -o test \
`pkg-config glfw3 --static --libs`
You may not need the --static flag if you have: libglfw3.dylib, as opposed to using: libglfw3.a, but it doesn't hurt.
If you are using Xcode, you must add the libglfw3.a library when linking binaries.
Heres the trick
Show hidden folders. Paste this into terminal: defaults write com.apple.finder AppleShowAllFiles YES
Relaunch a finder window and navigate to Macintosh HD\usr
Drag the usr folder to the "Favorites" side in the terminal
In xcode, click the add "+" to link binaries, then click "Add Other"
navigate to the libglfw3.a and add it!
If it still does not work, here are some instructions that helped me.
https://engineering-game-dev.com/2013/08/14/glfw-compiling-source-and-creating-an-xcode-project/comment-page-1/#comment-1400
First, I am sorry for my bad English, I am French.
I tried to install the Gtk+ library with Code::Blocks, and I created a project just for try to use the stuff.
So, I used the method given at this page :
http://forums.codeblocks.org/index.php?topic=16468.0
And I put this test code in main.c :
#include <stdlib.h>
#include <gtk/gtk.h>
void OnDestroy(GtkWidget *pWidget, gpointer pData);
int main(int argc,char **argv)
{
GtkWidget *pWindow;
gtk_init(&argc,&argv);
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(pWindow), GTK_WIN_POS_CENTER);
tk_window_set_default_size(GTK_WINDOW(pWindow), 320, 200);
gtk_window_set_title(GTK_WINDOW(pWindow), "Chapitre Fenetre");
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(OnDestroy), NULL);
gtk_widget_show(pWindow);
gtk_main();
return EXIT_SUCCESS;
}
void OnDestroy(GtkWidget *pWidget, gpointer pData)
{
gtk_main_quit();
}
And I tried to build, but I get this error on the Code::Blocks build log:
Execution of 'mingw32-g++.exe -o "bin\Debug\Simulation POP.exe" obj\Debug\main.o -LC:/MinGW/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl' in 'C:\Users\Habib\Documents\Simulation POP' failed.
Please, have-you got an explanation ?
Thanks you.
In fact, I desinstalled Code::Blocks, Gtk+ and all of the other stuff, and I just restart like this :
(1) C:\Program Files\Code::Blocks\
(2) C:\Program Files\Code::Blocks\Gtk+\
Then, I put the path (2)\bin\ in the Variable Path Environnement.
I configured Code::Blocks without the tutorial, just with the bin, gtk+ and lib directory.
I executed the main.c Hello Word, and everything was good.
If anyone has the same problem, just send me a mail or ask the question in the same topic.
I am on with trying to compile a simple GTK+ Hello World app on windows. I am following a tutorial from this url:
http://pandhare0.tripod.com/#mini-Tutorial
The contents of my HelloWorld.c is as follows and also taken from a wikipedia example:
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;
gtk_init (&argc, &argv);
/* create the main, top level, window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* give it the title */
gtk_window_set_title (GTK_WINDOW (window), "Hello World");
/* Connect the destroy signal of the window to gtk_main_quit
* When the window is about to be destroyed we get a notification and
* stop the main GTK+ loop
*/
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
/* Create the "Hello, World" label */
label = gtk_label_new ("Hello, World");
/* and insert it into the main window */
gtk_container_add (GTK_CONTAINER (window), label);
/* make sure that everything, window and label, are visible */
gtk_widget_show_all (window);
/* start the main loop, and let it rest there until the application is closed */
gtk_main ();
return 0;
}
I have followed the instructions to generate the build bat file and the contents of which are below:
path C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\%path%
gcc -Wall -g %1 -o %2 -mno-cygwin -mms-bitfields -IC:C:\gtk_2_22_x64\include\gtk-2.0 -IC:C:\gtk_2_22_x64\lib\gtk-2.0\include -IC:C:\gtk_2_22_x64\include\atk-1.0 -IC:C:\gtk_2_22_x64\include\cairo -IC:C:\gtk_2_22_x64\include\gdk-pixbuf-2.0 -IC:C:\gtk_2_22_x64\include\pango-1.0 -IC:C:\gtk_2_22_x64\include\glib-2.0 -IC:C:\gtk_2_22_x64\lib\glib-2.0\include -IC:C:\gtk_2_22_x64\include\pixman-1 -IC:C:\gtk_2_22_x64\include -IC:C:\gtk_2_22_x64\include\freetype2 -IC:C:\gtk_2_22_x64\include\libpng14 -LC:C:\gtk_2_22_x64\lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
%2
I have the MinGW inside my environment path. When I run the following command inside my command prompt:
gtkcmd.bat HelloWorld.c HelloWorld.exe
I get the following output:
C:\gtk+_compilation>gtkcmd.bat HelloWorld.c HelloWorld.exe
C:\gtk+_compilation>path C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\C:\MinGW\bin;C:C:\gt
k_2_22_x64\lib\C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\C:\MinGW\bin;C:C:\gtk_2_22_x64
\lib\C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\C:\MinGW\bin;C:\gtk_2_22_x64\lib\C:\MinG
W\bin;C:\gtk_2_22_x64\lib\C:\Program Files\Common Files\Microsoft Shared\Windows
Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windo
ws\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPower
Shell\v1.0\;C:\Program Files\Dell\Dell Wireless WLAN Card;c:\Program Files (x86)
\Common Files\Roxio Shared\10.0\DLLShared\;c:\Program Files (x86)\Common Files\R
oxio Shared\DLLShared\;C:\Program Files\TortoiseSVN\bin;c:\Program Files (x86)\M
icrosoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Windows Live\Shared;C:
\Program Files (x86)\IronPython 2.7;c:\Program Files (x86)\Microsoft ASP.NET\ASP
.NET Web Pages\v1.0\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\MinGW\bin;C:\gt
k_2_22_x64\bin;C:\gtk_2_22_x64\lib
C:\gtk+_compilation>gcc -Wall -g HelloWorld.c -o HelloWorld.exe -mno-cygwin -mms
-bitfields -IC:C:\gtk_2_22_x64\include\gtk-2.0 -IC:C:\gtk_2_22_x64\lib\gtk-2.0\i
nclude -IC:C:\gtk_2_22_x64\include\atk-1.0 -IC:C:\gtk_2_22_x64\include\cairo -IC
:C:\gtk_2_22_x64\include\gdk-pixbuf-2.0 -IC:C:\gtk_2_22_x64\include\pango-1.0 -I
C:C:\gtk_2_22_x64\include\glib-2.0 -IC:C:\gtk_2_22_x64\lib\glib-2.0\include -IC:
C:\gtk_2_22_x64\include\pixman-1 -IC:C:\gtk_2_22_x64\include -IC:C:\gtk_2_22_x64
\include\freetype2 -IC:C:\gtk_2_22_x64\include\libpng14 -LC:C:\gtk_2_22_x64\lib
-lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lp
angocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -
lgthread-2.0 -lglib-2.0 -lintl
HelloWorld.c:1:22: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
C:\gtk+_compilation>HelloWorld.exe
'HelloWorld.exe' is not recognized as an internal or external command,
operable program or batch file.
C:\gtk+_compilation>
Previously I had tried, strictly what the tutorial said, and used the / in the path statements as opposed to the full paths I now use. When I did use the / though it could not link anything. Every GTK statement returned an undefined error. So I have stayed with using the Full path in the header and linkers statements in the command line. As you can see from the above, it cannot find the gtk/gth.h header. This confuses me as I can clearly see the paths for such inside the command line arguments.
Any help is greatly appreciated.
Cheers,
Andrew
UPDATE:
Ok - I did screw up the bat file - daft mistakes but after correcting these inline with an answer below I now have the following bat file:
path \MinGW\bin;C:\gtk_2_22_x64\lib\%path%
gcc -Wall -g %1 -o %2 -mno-cygwin -mms-bitfields -IC:\gtk_2_22_x64\include\gtk-2.0 -IC:\gtk_2_22_x64\lib\gtk-2.0\include -IC:\gtk_2_22_x64\include\atk-1.0 -IC:\gtk_2_22_x64\include\cairo -IC:\gtk_2_22_x64\include\gdk-pixbuf-2.0 -IC:\gtk_2_22_x64\include\pango-1.0 -IC:\gtk_2_22_x64\include\glib-2.0 -IC:\gtk_2_22_x64\lib\glib-2.0\include -IC:\gtk_2_22_x64\include\pixman-1 -IC:\gtk_2_22_x64\include -IC:\gtk_2_22_x64\include\freetype2 -IC:\gtk_2_22_x64\include\libpng14 -LC:\gtk_2_22_x64\lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
%2
After this I now get the following errors from the compilation:
C:\Users\REA_AN~1\AppData\Local\Temp\cclrbtyP.o: In function `main':
C:\gtk+_compilation/HelloWorld.c:8: undefined reference to `gtk_init_abi_check'
C:\gtk+_compilation/HelloWorld.c:11: undefined reference to `gtk_window_new'
C:\gtk+_compilation/HelloWorld.c:14: undefined reference to `gtk_window_get_type
'
C:\gtk+_compilation/HelloWorld.c:14: undefined reference to `g_type_check_instan
ce_cast'
C:\gtk+_compilation/HelloWorld.c:14: undefined reference to `gtk_window_set_titl
e'
C:\gtk+_compilation/HelloWorld.c:20: undefined reference to `gtk_main_quit'
C:\gtk+_compilation/HelloWorld.c:20: undefined reference to `g_signal_connect_da
ta'
C:\gtk+_compilation/HelloWorld.c:23: undefined reference to `gtk_label_new'
C:\gtk+_compilation/HelloWorld.c:26: undefined reference to `gtk_container_get_t
ype'
C:\gtk+_compilation/HelloWorld.c:26: undefined reference to `g_type_check_instan
ce_cast'
C:\gtk+_compilation/HelloWorld.c:26: undefined reference to `gtk_container_add'
C:\gtk+_compilation/HelloWorld.c:29: undefined reference to `gtk_widget_show_all
'
C:\gtk+_compilation/HelloWorld.c:32: undefined reference to `gtk_main'
collect2: ld returned 1 exit status
It seems you folowed the instructions to create the .bat file incorrectly somehow - this:
-IC:C:\gtk_2_22_x64\include\gtk-2.0
should be:
-IC:\gtk_2_22_x64\include\gtk-2.0
and similar elsewhere. It looks like your path has got set up incorrectly - this:
path C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\%path%
should be:
path C:\MinGW\bin;C:\gtk_2_22_x64\lib\%path%
or something like it (note C:C: should be C:).
Edit: And now your problem is that the linker cannot find the libraries. The batch file should contain stuff like:
-L/path/to/gtk/libraries
but I don't know how you specify that when you create the file.