folder hierarchy on Linux

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
dave_kimble
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jun 21, 2018 1:56 am

folder hierarchy on Linux

Post by dave_kimble »

This is my very first C-wxWidgets attempt.
From https://wiki.wxwidgets.org/Compiling_an ... ng_started

Code: Select all

cd /path/to/wxWidgets-3.0.4
mkdir gtk-build
cd gtk-build
../configure
make
sudo make install
 
cd gtk-build/samples/minimal
make
./minimal
That works OK.
Now I want to compile my own C project in /path/to/wxWidgets-3.0.4/gtk-build/projects/frame/frame.c .

Code: Select all

cd /path/to/wxWidgets-3.0.4/gtk-build/projects/frame
g++ frame.c 'wx-config --cxxflags --libs' -o frametest
g++: error: wx-config --cxxflags --libs: No such file or directory

cd /path/to/wxWidgets-3.0.4/gtk-build
g++ ./projects/frame/frame.c 'wx-config --cxxflags --libs' -o frametest
g++: error: wx-config --cxxflags --libs: No such file or directory
Er ... , what is the correct hierarchy of folders to set up for my own stuff?
It is a pity "Compiling_and_getting_started" doesn't give one example of this.
I have tried using CodeLite and Code::Blocks IDEs and there is so much set up by default that I can't follow it.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: folder hierarchy on Linux

Post by DavidHart »

Hi,
'wx-config --cxxflags --libs'
Unless that's a copy/paste error, you are using single-quotes, which have no special meaning. They should be back-ticks (`) which say: "This is a separate command, kindly replace it with the output you get by running it".

(BTW, many people now use $(foo bar) instead of `foo bar` which at least has the advantage of being harder to misread.)
cd /path/to/wxWidgets-3.0.4/gtk-build
You don't want to pollute the wx build-dir with your code. Instead, point directly to the correct wx-config script. In an IDE's compiler/linker settings you'd use the full path; e.g.:
/path/to/wxWidgets-3.0.4/gtk-build/wx-config --cxxflags

In a terminal it's easier to prepend it to your $PATH:
PATH=/path/to/wxWidgets-3.0.4/gtk-build:$PATH

If you intend to use that wx build most/all of the time, you could put that line in your ~/.bashrc so that it's automatically run every time you open a terminal.

Regards,

David
dave_kimble
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jun 21, 2018 1:56 am

Re: folder hierarchy on Linux

Post by dave_kimble »

Thanks, I've been looking for that for days!
dave_kimble
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jun 21, 2018 1:56 am

Re: folder hierarchy on Linux

Post by dave_kimble »

So now a simplified script compiles OK, but when I run it, it seg faults with no visible output.

Terminal:

Code: Select all

PATH=/path/to/wxWidgets-3.0.4/gtk-build:$PATH
g++ /path/to/wxWidgets-3.0.4/gtk-build/projects/frame/frame2.c `wx-config --cxxflags --libs` -o frametest
Much cut down source "frame2.c":

Code: Select all

#include<wx/wx.h>
int main()
{      // data types
       wxFrame* frame;
       
       //create frame
       frame = new wxFrame(NULL, wxID_TOP, "Title" );
       frame->Show();
       return 0;
}
Terminal output:

Code: Select all

$ ./frametest

(process:3076): GLib-GObject-WARNING **: 10:29:34.595: invalid (NULL) pointer instance

(process:3076): GLib-GObject-CRITICAL **: 10:29:34.595: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(process:3076): Gdk-CRITICAL **: 10:29:34.595: IA__gdk_screen_get_default_colormap: assertion 'GDK_IS_SCREEN (screen)' failed

(process:3076): Gdk-CRITICAL **: 10:29:34.595: IA__gdk_colormap_get_visual: assertion 'GDK_IS_COLORMAP (colormap)' failed

(process:3076): Gdk-CRITICAL **: 10:29:34.595: IA__gdk_screen_get_default_colormap: assertion 'GDK_IS_SCREEN (screen)' failed

(process:3076): Gdk-CRITICAL **: 10:29:34.595: IA__gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed

(process:3076): Gdk-CRITICAL **: 10:29:34.595: IA__gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed

(process:3076): Gdk-CRITICAL **: 10:29:34.595: IA__gdk_window_new: assertion 'GDK_IS_WINDOW (parent)' failed
Segmentation fault (core dumped)
$ 
In case you are wondering, I am translating a wxPHP script written in procedural style, so I am trying to write C in procedural style.
Is that possible?
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: folder hierarchy on Linux

Post by DavidHart »

but when I run it, it seg faults with no visible output.
The generic answer to that is: rebuild with debug symbols (g++ -g ...) and run it in your debugger e.g. gdb. Then, when it seg-faults, 'bt' will show you a callstack (backtrace) of where the seg originates.

However, you do:
Much cut down source "frame2.c":
Unless that's so redacted as to be misleading, it looks as if you are providing your own main() and not using the standard IMPLEMENT_APP() macro. This means that the wx internals won't be properly initialised. Though providing your own main() is possible (see the unusually-well commented /path/to/wxWidgets-3.0.4/include/wx/app.h) it isn't advised.

Instead I strongly suggest you look at the 'minimal' sample in path/to/wxWidgets-3.0.4/samples/. The easiest way to get your program started the right way is to copy its code, then morph it to do what you need.
so I am trying to write C in procedural style.
There's no reason not to write your own code in procedural style, but don't try to inflict that on wx itself.
dave_kimble
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Jun 21, 2018 1:56 am

Re: folder hierarchy on Linux

Post by dave_kimble »

Thank you for the help.

I have already looked at /samples/minimal/minimal.cpp which is 200 lines. frame2.c is meant to be VERY minimal - 3 lines of code in wxPHP. I should come clean and admit I don't know C or C++ or OOP in any language, although I can see some benefits for working in teams on one project. I guess that comes from 51 years of coding the old way. I can't say programming has got any simpler in all that time, it seems to have gone backwards.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: folder hierarchy on Linux

Post by DavidHart »

I have already looked at /samples/minimal/minimal.cpp which is 200 lines. frame2.c is meant to be VERY minimal - 3 lines of code in wxPHP.
I don't know wxPHP but I suspect it does much the same as the C++ 'minimal' sample; it just hides it from you.

The code you posted can't work; it does the equivalent of getting into a car and expecting to travel without turning on the engine.

Don't write a main(). Put your code in MyApp::OnInit or MyFrame::MyFrame instead.
Post Reply