Add c++ support in a autotools project? - c++

I am now writing an app that need using c++ in my c code.My problem is i can't compile through the c++ code.
i have two source folders,cpp (contains only a c source file ) and src (contains only a c++ source file ).
my configure.in is just like this,very simple
AC_PREREQ([2.68])
AC_INIT([tste], [1.0], [ee#b.com])
AC_PROG_CXX
AC_PROG_CC
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE()
AC_CONFIG_FILES([Makefile cpp/Makefile src/Makefile] )
AC_OUTPUT
./Makefile.am:
SUBDIRS= src cpp
./cpp/Makefile.am:
bin_PROGRAMS=main
main_SOURCES=main.c
./src/Makefile.am:
bin_PROGRAMS=test
test_SOURCES=testcpp.cpp
When i using make to compile my project , the error occurs:
Making all in src
make[1]: Entering directory `/home/hujin/Desktop/test/src'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/hujin/Desktop/test/src'
Making all in cpp
make[1]: Entering directory `/home/hujin/Desktop/test/cpp'
make[1]: *** No rule to make target `main.o', needed by `main'. Stop.
make[1]: Leaving directory `/home/hujin/Desktop/test/cpp'
make: *** [all-recursive] Error 1

If I was in your skin, I wouldn't have split the project in submakefiles since it all goes to a single target ("tste").
You better put all of your source files in the root Makefile.am (you can generate more than one output from it):
# ./Makefile.am:
bin_PROGRAMS=main test
main_SOURCES=cpp/main.c
test_SOURCES=src/testcpp.cpp
Change your configure.acto something like:
# configure.ac
AC_PREREQ([2.68])
AC_INIT([tste], [1.0], [ee#b.com])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/testcpp.cpp])
AC_PROG_CXX
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
Then run:
aclocal && autoconf && automake
./configure
make
Here are some good links:
A tutorial for porting to autoconf & automake
Using Automake and Autoconf with C++
autotut: Using GNU auto{conf,make,header}

Related

autotools automake generated makefile does no work: make all-am

It took several painful days work to construct a autotools project. I got a configure file and it can generate a Makefile with several hundred lines of code. But when invoking make it only emits the following lines in 1 milliseconds.
make
make all-am
make[1]: Entering directory '/home/myacount/coding/orpara'
make[1]: Leaving directory '/home/myaccount/coding/orpara'
It seems that no work is done. The line that produced the output in the Makefile:
AUTOMAKE_OPTIONS = subdir-objects
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-am
My configure.ac file is not complicated:
....
AM_INIT_AUTOMAKE([-Wall -Werror])
AM_PROG_AR
AC_CONFIG_SRCDIR([src/interval.cpp])
AC_CONFIG_HEADERS([config.h])
LT_PREREQ([2.4])
LT_INIT([dlopen])
AC_CONFIG_MACRO_DIR([m4])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_INSTALL
AC_LANG([C], [C++])
# Checks for libraries.
I have no clue where to start my debug. I am using automake to generate the makefile.
My Makefile.am in the top level directory is simple:
ACLOCAL_AMFLAGS = -I m4
SUBIDRS = src
The Makefile.am in the src directory has two targets (the PROGRAM primary is for testing only)
bin_PROGRAMS = GrishinDistance
GrishinDistance_SOURCES=GrishinDistance.cpp
Not showing the Makefile.am in subdir seqaln.
My problem is with the Makfile.am in the top directory:
SUBIDRS = src
A typo error with SUBDIRS => SUBIDRS.
If others have similar problem, you should be looking into these typo errors.

What is the best way to build the GNU Scientific Library for use on MinGW?

I'm trying to get GSL version 1.16 built using MinGW but I'm running into some problems. I followed these instructions which involve invoking these commands from within sh.exe.
tar zxvf <the name of your gsl source package>
cd gsl-<the version number of your gsl source package>
./configure --enable-static=yes --enable-shared=yes --prefix=/c/GSL-<version number of gsl source package>
make
make install
I obtained these messages before make gave up.
/usr/bin/sed: can't read <my last name>/gsl-1.16/cblas/libgslcblas.la: No such file or directory
libtool: link: `<my last name>/gsl-1.16/cblas/libgslcblas.la' is not a valid libtool archive
make[2]: *** [libgsl.la] Error 1
make[2]: Leaving directory `/usr/home/<my full name>/gsl-1.16'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/home/<my full name>/gsl-1.16'
make: *** [all] Error 2
Can anyone explain this? Could it be something to do with one of the file paths involving a space between my first last names? Alternatively, does anyone know of me another way to install the GSL which has definitely worked for them?

Makefile install target sometimes working, sometimes not

I'm currently working on a project that should also provide a source package to be packaged into linux systems. Since I'm using monodevelop, I used
mdtool generate-makefiles AudioCuesheetEditor.sln --simple-makefiles
to generate makefiles,etc. But there is a little problem. On some system everything works fine when running the last step
make install
but sometimes not. The output then says
[root#VMFedora17 Downloads]# make install
make[1]: Entering directory `/home/sven/Downloads'
make[1]: Leaving directory `/home/sven/Downloads'
make[1]: Entering directory `/home/sven/Downloads'
make pre-install-local-hook prefix=/usr/local
make[2]: Entering directory `/home/sven/Downloads'
make[2]: Leaving directory `/home/sven/Downloads'
make install-satellite-assemblies prefix=/usr/local
make[2]: Entering directory `/home/sven/Downloads'
mkdir -p '/usr/local/lib'
cp bin/Release /usr/local/lib/AudioCuesheetEditor
cp: omitting directory `bin/Release'
make[2]: *** [/usr/local/lib/AudioCuesheetEditor] Error 1
make[2]: Leaving directory `/home/sven/Downloads'
make[1]: *** [install-local] Error 2
make[1]: Leaving directory `/home/sven/Downloads'
make: *** [install-recursive] Error 1
This was run on a Fedora 17 Linux with KDE installed. On another Fedora 17 KDE everything went perfect.
Could somebody help me, where the error is?
Makefile can be found here: http://sourceforge.net/p/audiocuesheet/code/140/tree/trunk/Quellcode/AudioCuesheetEditor.make
Thanks for your help!
From your output and the link you provided, I found the error in the following snippet:
install-local: $(ASSEMBLY) $(ASSEMBLY_MDB)
make pre-install-local-hook prefix=$(prefix)
make install-satellite-assemblies prefix=$(prefix)
mkdir -p '$(DESTDIR)$(libdir)/$(PACKAGE)'
$(call cp,$(ASSEMBLY),$(DESTDIR)$(libdir)/$(PACKAGE))
I guess $(ASSEMBLY) was a directory, but I am not sure. And the command cp without the parameter -r will not copy the directory recursively. You can try to modify
$(call cp,$(ASSEMBLY),$(DESTDIR)$(libdir)/$(PACKAGE))
to
$(call cp,-r,$(ASSEMBLY),$(DESTDIR)$(libdir)/$(PACKAGE))
or
cp -r $(ASSEMBLY) $(DESTDIR)$(libdir)/$(PACKAGE)
Additionally, if you want to find out why the original works on one machine but not on the another, you can add a command:
echo $(ASSEMBLY)
before the above command to see if the output of them are different on different machines.

Error while compiling library for ARM platform

I'm using my toolchain to compile gst-plugins-bad for ARM. I compiled everything that should be needed to build it, including gstreamer, libmms etc... and placed in my sysroot both the headers, the libraries and files related to pkg-config.
When I configure everyrhing seems ok, but trying to compile results in:
luca#luca-work-laptop:~/gstreamer/gst-plugins-bad-0.10.21$ make
make all-recursive
make[1]: Entering directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21'
Making all in gst-libs
make[2]: Entering directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs'
Making all in gst
make[3]: Entering directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst'
Making all in interfaces
make[4]: Entering directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst/interfaces'
make all-am
make[5]: Entering directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst/interfaces'
make[5]: Nothing to be done for `all-am'.
make[5]: Leaving directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst/interfaces'
make[4]: Leaving directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst/interfaces'
Making all in signalprocessor
make[4]: Entering directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst/signalprocessor'
make[4]: Nothing to be done for `all'.
make[4]: Leaving directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst/signalprocessor'
Making all in video
make[4]: Entering directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst/video'
CC libgstbasevideo_0.10_la-gstbasevideoutils.lo
CC libgstbasevideo_0.10_la-gstbasevideocodec.lo
CC libgstbasevideo_0.10_la-gstbasevideodecoder.lo
CC libgstbasevideo_0.10_la-gstbasevideoencoder.lo
CC libgstbasevideo_0.10_la-gstbasevideoparse.lo
CCLD libgstbasevideo-0.10.la
libtool: link: warning: library `/home/luca/.../arm-2010q1_vsync/arm-none-linux-gnueabi/libc/usr/lib/libgstbase-0.10.la' was moved.
libtool: link: warning: library `/home/luca/.../arm-2010q1_vsync/arm-none-linux-gnueabi/libc/usr/lib/libgstreamer-0.10.la' was moved.
libtool: link: warning: library `/home/luca/.../arm-2010q1_vsync/arm-none-linux-gnueabi/libc/usr/lib/libgobject-2.0.la' was moved.
libtool: link: warning: library `/home/luca/.../arm-2010q1_vsync/arm-none-linux-gnueabi/libc/usr/lib/libgmodule-2.0.la' was moved.
libtool: link: warning: library `/home/luca/.../arm-2010q1_vsync/arm-none-linux-gnueabi/libc/usr/lib/libgthread-2.0.la' was moved.
libtool: link: warning: library `/home/luca/.../arm-2010q1_vsync/arm-none-linux-gnueabi/libc/usr/lib/libglib-2.0.la' was moved.
libtool: link: warning: library `/home/luca/.../arm-2010q1_vsync/arm-none-linux-gnueabi/libc/usr/lib/libgstvideo-0.10.la' was moved.
/usr/lib/libxml2.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[4]: *** [libgstbasevideo-0.10.la] Error 1
make[4]: Leaving directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst/video'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs/gst'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21/gst-libs'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/luca/gstreamer/gst-plugins-bad-0.10.21'
make: *** [all] Error 2
It seems it is trying to link against my desktop libxml2. Why isn't it linking against the one I have in my toolchain which has all the symbols?
Does your configure script support autoconf cross-compilation ?
In the configure.in , what is the value of the shell variable cross_compiling after calling AC_PROG_CC ?
If it is set to no, then is the makefile set to use your cross compiler ?
To set these you can either override them in the manual or use environment variables like
the example below
export CC=arch-gcc
export CXX=arch-c++
export arch-ld
export AR=arch-ar
export AS=arch-as
export NM=arch-nm
export STRIP=arch-strip
If it is set to yes, then check the include path specifically for libxml in the makefile.
Another possible resource for compiling gst-plugins-bad on ARM is the following guide
Are you sure your toolchain has libxml2? Or rather, your sysroot.
You might need to export PKG_CONFIG, so when you run 'pkg-config --libs libxml-2.0' you get the right path. Also, you can check the resulting Makefile to see what are the real flags used, or build with the verbose option on.
It's also possible that GStreamer's build stuff is broken for cross-compilation, which is one of the reasons I use scratchbox 2; it makes cross-compilation transparent.

gcc 4.5 installation problem under ubuntu

I tried to install gcc 4.5 on ubuntu 10.04 but failed.
Here is a compile error that I don't know how to solve. Is there anyone successfully install the latest gcc on ubuntu?
Following is my steps and the error message, I'd like to know where is the problem....
Step1: download these files:
gcc-core-4.5.0.tar.gz
gcc-g++-4.5.0.tar.gz
gmp-4.3.2.tar.bz2
mpc-0.8.1.tar.gz
mpfr-2.4.2.tar.gz
Step2: Unzip above files
Step3: move gmp, mpc, mpfr to the gcc-4.5.0/ directory.
mv gmp-4.3.2 gcc-4.5.0/gmp
mv mpc-0.8.1 gcc-4.5.0/mpc
mv mpfr-2.4.2 gcc-4.5.0/mpfr
Step4: go to gcc-4.5.0 directory and do configuration:
sudo ./configure
Step5: compile and install
sudo make
sudo make install
The first 4 steps is OK, I can configure it successfully. However, when I try to compile it, following error message comes out, I cannot figure out what the problem is. Should I change the name from "gcc 4.5" to "gcc"?? It's a little strange that we need to do this by ourself. Is there anything I missed during the installation?
xxx#xxx-laptop:/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0$ sudo make
[sudo] password for xxx:
[ -f stage_final ] || echo stage3 > stage_final
/bin/bash: line 2: test: /media/Data/Tool/linux/gcc: binary operator expected
/bin/bash: /media/Data/Tool/linux/gcc: No such file or directory
make[1]: Entering directory `/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0'
make[2]: Entering directory `/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0'
make[3]: Entering directory `/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0'
rm -f stage_current
make[3]: Leaving directory `/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0'
make[2]: Leaving directory `/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0'
make[2]: Entering directory `/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0'
Configuring stage 1 in host-x86_64-unknown-linux-gnu/intl
/bin/bash: /media/Data/Tool/linux/gcc: No such file or directory
make[2]: *** [configure-stage1-intl] Error 127
make[2]: Leaving directory `/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/media/Data/Tool/linux/gcc 4.5/gcc-4.5.0'
make: *** [all] Error 2
It might not be a good idea to have a space in your path - it's kind of rare and can easily mess up shell scripts that aren't specially designed to deal with it (which is a bad combination!)
Another potential problem is that you're running configure inside the gcc source directory - this isn't recommended (and didn't work at all for me on at least one version of gcc 4). Instead make an empty build directory, parallel to the source directory, so you have something like:
gcc 4.5 <- but might want to avoid the space
gcc-4.5.0
...
build
Then cd into build and run
../gcc-4.5.0/configure
You may also need to start from a freshly unzipped source directory, as the previous failed build may have broken it.