Trouble compiling /samples/artprov Topic is solved

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
Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Trouble compiling /samples/artprov

Post by Nick » Sat Aug 17, 2019 3:52 pm

I don't know if I'm doing it correctly, but I can't compile this example I downloaded:
https://github.com/wxWidgets/wxWidgets/ ... es/artprov

Tried as below, using g++ I'm a Linux user (Slackware)
g++ artbrows.cpp artbrows.h arttest.cpp `wx-config --libs --cxxflags`
g++ artbrows.cpp artbrows.h `wx-config --libs --cxxflags`
g++ arttest.cpp `wx-config --libs --cxxflags`

None of the 3 ways I tried above worked

OBS I fixed this my gcc text for g++. Because I made a mistake writing gcc here instead of g++ but I didn't do it wrong when I was trying to compile
Last edited by Nick on Sun Aug 18, 2019 5:42 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 13989
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Trouble compiling /samples/artprov

Post by doublemax » Sat Aug 17, 2019 4:40 pm

What errors are you getting?
Can you build the "minimal" sample?

Use the makefile that's inside the directory for each sample.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2024
Joined: Sun Jan 03, 2010 5:45 pm

Re: Trouble compiling /samples/artprov

Post by PB » Sat Aug 17, 2019 7:08 pm

doublemax wrote:
Sat Aug 17, 2019 4:40 pm
Use the makefile that's inside the directory for each sample.
I am not using Linux but I believe that the makefiles in individual samples' directories are for Windows (MinGW) only. On Linux the makefiles for samples are produced in the build dir for the library. I assume you are familiar with the official install instructions but they were of no help and neither was the guide on wxWiki? I once tried Linux and I think I got the samples built using this guide: https://www.binarytides.com/install-wxwidgets-ubuntu/

DavidHart
Site Admin
Site Admin
Posts: 3881
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Trouble compiling /samples/artprov

Post by DavidHart » Sat Aug 17, 2019 8:47 pm

Hi,

As you've already been told, the sensible way to build the samples is to cd into the build dir, then run 'make'.

However, I just tested what you were trying. After pointing the terminal's PATH to the install dir:
PATH=/full/path/to/wxWidgets-3.0.4/install_dir:$PATH
I tried your first line.
gcc artbrows.cpp artbrows.h arttest.cpp `wx-config --libs --cxxflags`
It didn't work. I removed the unnecessary header file; no improvement.

I then s/gcc/g++ (wx is a C++ library):

Code: Select all

g++ artbrows.cpp  arttest.cpp `wx-config --libs --cxxflags`
Success!

Using the makefile is a lot easier, though...

Regards,

David

Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Re: Trouble compiling /samples/artprov

Post by Nick » Sat Aug 17, 2019 10:23 pm

DavidHart wrote:
Sat Aug 17, 2019 8:47 pm
As you've already been told, the sensible way to build the samples is to cd into the build dir, then run 'make'.
I don't think I know how to use make correctly. With some programs I just type make and it works but that's not the case
See what I tried:

Code: Select all

bash-4.4$ make
make: *** No targets specified and no makefile found.  Stop.
bash-4.4$ make artbrows.cpp 
make: Nothing to be done for 'artbrows.cpp'.
bash-4.4$ make arttest.cpp 
make: Nothing to be done for 'arttest.cpp'.
bash-4.4$ make artbrows.cpp arttest.cpp 
make: Nothing to be done for 'artbrows.cpp'.
make: Nothing to be done for 'arttest.cpp'.
bash-4.4$ 

Code: Select all

g++ artbrows.cpp  arttest.cpp `wx-config --libs --cxxflags`
Success!
David
That way you reported it also compiled here. Without the .h File

Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Re: Trouble compiling /samples/artprov

Post by Nick » Sat Aug 17, 2019 10:26 pm

PB wrote:
Sat Aug 17, 2019 7:08 pm
I am not using Linux but I believe that the makefiles in individual samples' directories are for Windows (MinGW) only. On Linux the makefiles for samples are produced in the build dir for the library. I assume you are familiar with the official install instructions but they were of no help and neither was the guide on wxWiki? I once tried Linux and I think I got the samples built using this guide: https://www.binarytides.com/install-wxwidgets-ubuntu/
Thanks for the links, information always helps!

User avatar
doublemax
Moderator
Moderator
Posts: 13989
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Trouble compiling /samples/artprov

Post by doublemax » Sat Aug 17, 2019 11:44 pm

bash-4.4$ make
make: *** No targets specified and no makefile found. Stop.
You were probably in the wrong directory.

Like PB said:
On Linux the makefiles for samples are produced in the build dir for the library.
Use the source, Luke!

Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Post by Nick » Sun Aug 18, 2019 5:40 pm

I edited this post because the solution I provided is wrong, since right below DavidHart corrects what I reported here.
So to avoid this confusing other people I deleted the wrong solution. :roll:
Last edited by Nick on Sun Aug 18, 2019 9:11 pm, edited 1 time in total.

DavidHart
Site Admin
Site Admin
Posts: 3881
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Trouble compiling /samples/artprov

Post by DavidHart » Sun Aug 18, 2019 8:19 pm

I consider a BUG maybe! I believe artbrows.h was written incorrectly
No, it's fine. You are just trying
1) to do something wrong
2) and doing it in the wrong way.

1) Don't try to build the code directly with g++. Use the makefile that was set up correctly when you configured wxWidgets. It will be in the dir where you built wx.

2) When you must build a binary directly with g++ (because there isn't an easy way e.g. a makefile), don't try to build header files too. Header files are #included from cpp files.

If you look at arttest.cpp you will see that it #includes wx/artbrows.h. Look harder and you will see that it does this after doing #include "wx/wx.h". I haven't checked, but almost certainly wx/wx.h will already have done #include <wx/stattext.h> and #include <wx/choice.h>, which is why compiling just the cpp files works.

'If it ain't broke, don't fix it'; and if you really, really want to fix it, don't fix it badly ;) .

Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Re: Trouble compiling /samples/artprov

Post by Nick » Sun Aug 18, 2019 9:06 pm

DavidHart wrote:
Sun Aug 18, 2019 8:19 pm
1) Don't try to build the code directly with g++. Use the makefile that was set up correctly when you configured wxWidgets. It will be in the dir where you built wx.

2) When you must build a binary directly with g++ (because there isn't an easy way e.g. a makefile),
I think I'm having trouble with that.
I can't compile using make. I tried either as a normal user or as root

Code: Select all

bash-4.4# pwd
/mnt/dados/Downloads/wxWidgets-3.1.2/samples
bash-4.4# make
make: *** No targets specified and no makefile found.  Stop.
bash-4.4# cd richtext
bash-4.4# pwd
/mnt/dados/Downloads/wxWidgets-3.1.2/samples/richtext
bash-4.4# make
make: *** No targets specified and no makefile found.  Stop.
I believe I didn't understand how to use make in this example folder
Can you point me one way how I use make to compile these examples? I have no idea where I'm going wrong
The example samples/richtext, It doesn't compile at all because it gives a lot of errors using g++ and I don't know how to make make it work on it.

DavidHart
Site Admin
Site Admin
Posts: 3881
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Trouble compiling /samples/artprov

Post by DavidHart » Sun Aug 18, 2019 9:32 pm

I can't compile using make.
I believe I didn't understand how to use make in this example folder
Can you point me one way how I use make to compile these examples? I have no idea where I'm going wrong
Let's go back to the beginning.
You downloaded wxWidgets-3.1.2. What did you do then? Did you configure and build it? If so, how and where?

If you didn't build wxWidgets-3.1.2, what is your wxWidgets install? You must have one as `wx-config --libs --cxxflags` works. Where is it, and which wx version?

Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Re: Trouble compiling /samples/artprov

Post by Nick » Sun Aug 18, 2019 10:32 pm

DavidHart wrote:
Sun Aug 18, 2019 9:32 pm
Let's go back to the beginning.
You downloaded wxWidgets-3.1.2. What did you do then? Did you configure and build it? If so, how and where?
If you didn't build wxWidgets-3.1.2, what is your wxWidgets install? You must have one as `wx-config --libs --cxxflags` works. Where is it, and which wx version?
I consider myself a beginner in programming for many reasons. I already created small programs using Delphi, then I wanted to learn C++ but I was still using Borland tools, I used RadStudio at the time. At that time I still used windows. I gave up on him for losing data and things I couldn't lose. And I went to Linux. In Linux I found that I don't know how to program. I was sad about it! Because Borland tools do everything.

So I decided to learn C, read some books I downloaded from the Internet, and google it. A long way I know. But I need to create a database for my use, where I register what I learn.

Learning C, I discovered that it would not be so simple to have a form. so I discovered wxWidgets. Reading about her, I enjoyed it a lot. I liked it even more when I learned that even though I was a Linux user, I could compile windows programs. At first glance I found it super complicated. But compared to others, I identified myself the most.

After that I realized that writing the code by hand only one notepad and wxWidgets would initially be very difficult. And I would need an IDE
I use Slackware, I installed Eclipse, Netbeans and Codeblocks 17.12

Codeblocks 17.12 although it gave me a lot of work to install and make it work with wxSmith was worth it. He has helped me with his automatic codes to understand how they work: statements, controls, and so on. But of course I realized that the code he writes is old many times, and writes more than I need.

I before Codeblocks I installed wxWidgets 3.1.2.

Currently what I have been doing is writing wxWidgets code in the editor (Atom) manually. So that I can understand how each separate control works. Every statement, every widgets. All written by hand.

I created a minimum code, with only 1 window. Then I just added 1 button ... I got my questions here in the forum with what I do not understand.
My goal is to know what it means and what it does, every word I write in the code.

Progress:
Today I already understand the classes better. I learned how to read in wxWidgets Internet docs about classes and better understand how they work, commands, controls, ways to declare. Of course I still have difficulties that I am clearing my doubts here in the Forum.

RESUME
I use wxWidgets v.3.1.2 with Slackware64-Current, gcc v.8.2
I use the Editor (Atom) Simple Text Editor. To write what I am learning, and compile by the terminal with the commands below.:

Code: Select all

g++ Test.cpp `wx-config --libs --cxxflags` -o Test
I don't know if it's the right way to compile, but that's what I found on the Internet and it has worked

Sometimes I use Codeblocks, To put some control that I don't know how to declare, and study the way it did, then I try to simplify and go to other examples on the Internet to compare and filter to make the best and most correct possible.

My ultimate goal when I really learn would be to use Codeblocks just to inform me X and Y of the controls.

The wxWidgets, I downloaded the source and created a package for Slackware with the script below.

Code: Select all

#!/bin/sh

set -e

PKGNAME=wxWidgets
VERSION=${VERSION:-3.1.2}
BUILD=${BUILD:-1}
TAG=${TAG:-_Hcs}
ARCH=${ARCH:-x86_64}

SOURCE="$PKGNAME-$VERSION.tar.bz2"

TAR=      # empty = auto
DIR=      # empty = auto
DOCS="docs/*"
SLKFILES="" 

JOBS=${JOBS:--j2}
CWD=$(pwd)
TMP=${TMP:-/tmp/Hcs/$PKGNAME}
PKG=$TMP/package-$PKGNAME
OUTPUT=${OUTPUT:-$CWD}
TAR=${TAR:-$(basename $SOURCE)}
DIR=${DIR:-$(echo "$TAR"|sed -r 's/(\.tar|)(.gz|.bz2|.xz|)$//')}

if [ ! -e $CWD/$TAR ];then
  wget $SOURCE -O "$CWD/$TAR"
fi

CHOST="i486"
if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
  CHOST="x86_64"
fi

rm -rf $TMP
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
tar xjf $CWD/$TAR
cd $DIR

chmod -R u+w,go+r-w,a-s .

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --libdir=/usr/lib$LIBDIRSUFFIX \
  --sysconfdir=/etc \
  --localstatedir=/var \
  --mandir=/usr/man \
  --enable-unicode \
  --enable-plugins \
  --with-sdl \
  --with-opengl \
  --with-libmspack \
  --build=$CHOST-slackware-linux
make
make install DESTDIR=$PKG

mkdir -p $PKG/usr/doc/$PKGNAME-$VERSION
cp -r $DOCS $PKG/usr/doc/$PKGNAME-$VERSION
 
mkdir -p $PKG/usr/doc/$PKGNAME-$VERSION/SlackBuild
cd $CWD
for SB in $PKGNAME.SlackBuild slack-desc doinst.sh doinst.sh.gz EULA.TXT $SLKFILES;do
  [ -e $SB ]&&cp -r $SB $PKG/usr/doc/$PKGNAME-$VERSION/SlackBuild/$SB
done

if [ -d $PKG/usr/man ]; then
    ( cd $PKG/usr/man
      find . -type f -exec gzip -9 {} \;
      for i in $( find . -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
    )
fi

( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs -r strip --strip-unneeded 2> /dev/null || true
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs -r strip --strip-unneeded 2> /dev/null || true
  find . | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs -r strip --strip-unneeded 2> /dev/null || true
)

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
[ -e $CWD/doinst.sh ] && cat $CWD/doinst.sh > $PKG/install/doinst.sh
[ -e $CWD/doinst.sh.gz ] && zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

cd $PKG
chown -R root:root $PKG

if [ -x "$(which requiredbuilder 2>/dev/null)" ];then
  requiredbuilder -y -v -s $CWD $PKG   # add "-c -b" if you have binary files in /usr/share 
  [ -e install/slack-required ]&&cat install/slack-required > $PKG/usr/doc/$PKGNAME-$VERSION/SlackBuild/slack-required
fi

/sbin/makepkg -l y -c n $OUTPUT/$PKGNAME-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-txz}

if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP
fi

DavidHart
Site Admin
Site Admin
Posts: 3881
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Trouble compiling /samples/artprov

Post by DavidHart » Mon Aug 19, 2019 9:34 am

So, to summarise, you have a system install of wx3.1.2 that (afaict) doesn't provide the samples.

You also downloaded the wx3.1.2 source package but didn't build it. You need to do so.

I strongly suggest you create a 'local' build as follows:

Code: Select all

cd /full/path/to/your/wx3.1.2-source
mkdir build-dir && cd build-dir
../configure --enable-debug  --prefix=`pwd`
make -j2
This builds wx to match the system one, but leaves it isolated in build-dir. You don't need to install it.

If you then cd samples/artprov and run 'make', it should build. And so should the other samples.

Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Re: Trouble compiling /samples/artprov

Post by Nick » Mon Aug 19, 2019 5:23 pm

DavidHart wrote:
Mon Aug 19, 2019 9:34 am
So, to summarise, you have a system install of wx3.1.2 that (afaict) doesn't provide the samples.

You also downloaded the wx3.1.2 source package but didn't build it. You need to do so.

I strongly suggest you create a 'local' build as follows:

Code: Select all

cd /full/path/to/your/wx3.1.2-source
mkdir build-dir && cd build-dir
../configure --enable-debug  --prefix=`pwd`
make -j2
This builds wx to match the system one, but leaves it isolated in build-dir. You don't need to install it.

If you then cd samples/artprov and run 'make', it should build. And so should the other samples.
RESUME It worked! Really enjoyed. Because I can make good use of these examples.

If you can help me understand what we did.
What I know: I unzipped the Source. I created a folder inside it. And inside this folder I executed the command:
../configure --enable-debug --prefix=`pwd`
make -j2

Thanks for the lesson!
This command executed /configure from wxWidgets Source: ie in the folder wxWidgets-3.1.2
I didn't understand what you do: --prefix=`pwd`

and make -j2 Compiled a few things for the folder that was created. And created makefiles in folders where there were sources

Is this build-dir folder the entire wxWidgets compiled or just prepared to create the necessary makefile?
What is -j2

DavidHart
Site Admin
Site Admin
Posts: 3881
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Trouble compiling /samples/artprov

Post by DavidHart » Mon Aug 19, 2019 6:39 pm

I didn't understand what you do: --prefix=`pwd`
The backticks execute whatever is inside them. So you earlier did
`wx-config --libs --cxxflags`
which calls the wx-config script and tells it to output its cxx flags and (standard) libs (try doing it in a terminal without the backticks).
The command pwd outputs the current dir. So if that is /home/nick/devel/wx3.1.2/build-dir, it outputs that. And --prefix= says to 'install' the wx build there, instead of the default /usr/local/.
Is this build-dir folder the entire wxWidgets compiled
Yes
What is -j2
-j<number of jobs>
I put '2' because that's what your wx slackbuild used. If your cpu has 4 cores, use -j4 and it will build 4 times as fast as the default -j1.

Post Reply