help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: makefile for generating exe from single cpp


From: Amit Chaudhuri
Subject: Re: makefile for generating exe from single cpp
Date: Sat, 18 Oct 2014 07:48:10 +0100

Hi Paul,

thanks for the initial idea.  Below the contents  the directory (stuff
is a subdir with longer version of main.cpp and some other makefiles),
followed by cat of main and makefile.  Next is the results of make -n
followed by the first couple of lines of the linker moan..I have not
included the error message.

Finally, I'm wondering about the environment, so I have appended the
results of env also.  Can't see any default values for compiler etc.

Regards,
Amit

address@hidden:~/prog/cpp/test> ls
main.cpp  makefile  stuff
address@hidden:~/prog/cpp/test> cat main.cpp
#include <iostream>
#include <set>

using std::set;
using std::cout;
using std::endl;

template<typename T> void dump(const set<T>& s)
{
        int num = s.size();
        cout << "size: " << num << endl;
        typename set<T>::const_iterator it = s.begin(), itend = s.end();
        for (; it != itend; ++it)
        {
                --num;
                cout << *it;
                cout << (num > 0 ? " : " : "");
        }
        cout << endl;
}

/* Experiments with std::set
 *
 */
int main( int argc, char *argv[])
{
        // data
        //
        set<int> one;
        one.insert(1);
        one.insert(2);
        one.insert(3);
        one.insert(14); // (1) = 4, (2) = 14

        cout << "set one " ;
        dump(one);

        return 0;
}
address@hidden:~/prog/cpp/test> cat makefile
main: main.o

address@hidden:~/prog/cpp/test> make -n
g++    -c -o main.o main.cpp
cc   main.o   -o main



main.o: In function `main':
main.cpp:(.text+0xf2): undefined reference to `std::cout'
main.cpp:(.text+0xf7): undefined reference to
`std::basic_ostream<char, std::char_traits<char> >& std::operator<<
<std::cha



address@hidden:~/prog/cpp/test> env
LESSKEY=/etc/lesskey.bin
XDG_VTNR=7
MANPATH=/usr/lib64/mpi/gcc/openmpi/share/man:/usr/local/man:/usr/share/man:/opt/kde3/share/man:/opt/dx/man
NNTPSERVER=news
SSH_AGENT_PID=2631
KDE_MULTIHEAD=false
XDG_SESSION_ID=1
DM_CONTROL=/var/run/xdmctl
HOSTNAME=linux-erag
XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
GPG_AGENT_INFO=/tmp/gpg-xhgyHQ/S.gpg-agent:2630:1
TERM=xterm
SHELL=/bin/bash
HOST=linux-erag
HISTSIZE=1000
XDG_SESSION_COOKIE=5449f3a160e9d808373a12d400002a68-1413613874.46869-1140620150
XDM_MANAGED=method=classic,auto
PROFILEREAD=true
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/amit/.gtkrc-2.0:/home/amit/.kde4/share/config/gtkrc-2.0
KONSOLE_DBUS_SERVICE=:1.86
TMPDIR=/tmp
PERL5LIB=/usr/lib/perl5/vendor_perl
KONSOLE_PROFILE_NAME=Shell
GTK_RC_FILES=/etc/gtk/gtkrc:/home/amit/.gtkrc:/home/amit/.kde4/share/config/gtkrc
GS_LIB=/home/amit/.fonts
WINDOWID=100663339
MORE=-sl
XSESSION_IS_UP=yes
SHELL_SESSION_ID=da1253215eac4000a3b22693466145db
GTK_MODULES=canberra-gtk-module
KDE_FULL_SESSION=true
USER=amit
JRE_HOME=/usr/lib64/jvm/jre
LS_COLORS=no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.xz=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:
LD_LIBRARY_PATH=/usr/lib64/mpi/gcc/openmpi/lib64
XNLSPATH=/usr/share/X11/nls
HOSTTYPE=x86_64
QEMU_AUDIO_DRV=pa
SSH_AUTH_SOCK=/tmp/ssh-ABbqGPWKylow/agent.2618
FROM_HEADER=
SESSION_MANAGER=local/linux-erag:@/tmp/.ICE-unix/2726,unix/linux-erag:/tmp/.ICE-unix/2726
OOO_FORCE_DESKTOP=gnome
CONFIG_SITE=/usr/share/site/x86_64-unknown-linux-gnu
PAGER=less
CSHEDIT=emacs
XDG_CONFIG_DIRS=/etc/xdg
MINICOM=-c on
DESKTOP_SESSION=default
PATH=/usr/lib64/mpi/gcc/openmpi/bin:/home/amit/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin
MAIL=/var/spool/mail/amit
CPU=x86_64
QT_IM_MODULE=ibus
JAVA_BINDIR=/usr/lib64/jvm/jre/bin
PWD=/home/amit/prog/cpp/test
INPUTRC=/home/amit/.inputrc
address@hidden
JAVA_HOME=/usr/lib64/jvm/jre
LANG=en_GB.UTF-8
KDE_SESSION_UID=1000
PYTHONSTARTUP=/etc/pythonstart
KONSOLE_DBUS_SESSION=/Sessions/2
SSH_ASKPASS=/usr/lib/ssh/ssh-askpass
GPG_TTY=/dev/pts/11
AUDIODRIVER=pulseaudio
COLORFGBG=15;0
QT_SYSTEM_DIR=/usr/share/desktop-data
SHLVL=2
XDG_SEAT=seat0
HOME=/home/amit
OSTYPE=linux
KDE_SESSION_VERSION=4
ALSA_CONFIG_PATH=/etc/alsa-pulse.conf
SDL_AUDIODRIVER=pulse
LANGUAGE=
LESS_ADVANCED_PREPROCESSOR=no
LS_OPTIONS=-N --color=tty -T 0
XCURSOR_THEME=DMZ
WINDOWMANAGER=/usr/bin/startkde
LESS=-M -I -R
address@hidden,UTF-8,ISO-8859-15,CP1252
LOGNAME=amit
MACHTYPE=x86_64-suse-linux
CVS_RSH=ssh
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-XQHQaezFBw,guid=80f8a33069aeddc8f821721b54420930
XDG_DATA_DIRS=/usr/share:/usr/share:/etc/opt/kde3/share:/opt/kde3/share
LESSOPEN=lessopen.sh %s
USE_FAM=
WINDOWPATH=7
PROFILEHOME=
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
QT_PLUGIN_PATH=/home/amit/.kde4/lib64/kde4/plugins/:/usr/lib64/kde4/plugins/
XDG_CURRENT_DESKTOP=KDE
GTK_IM_MODULE=ibus
XAUTHLOCALHOSTNAME=linux-erag
LESSCLOSE=lessclose.sh %s %s
QT_IM_SWITCHER=imsw-multi
G_BROKEN_FILENAMES=1
COLORTERM=1
JAVA_ROOT=/usr/lib64/jvm/jre



On Fri, Oct 17, 2014 at 1:51 PM, Paul Smith <address@hidden> wrote:
> On Fri, 2014-10-17 at 07:46 +0100, Amit Chaudhuri wrote:
>> my reading of the manual for GNU make (v3.82) was that a simple
>> makefile consisting of:
>>
>> main: main.o
>>
>> in a project consisting of a single main.cpp file would invoke g++ and
>> generate .o from .cpp and main by linking with g++.
>
> That is true.
>
>> This is not what I see and it comes as a surprise.
>>
>> The first implicit rule picked up is to link main from main.o with cc
>> rather than g++.
>
> If you provide us the output of the make command we can be more helpful.
> My suspicion is you have both a "main.c" and a "main.cpp" in your
> directory.  Since you don't specify which source file should be used to
> build the object file, make uses rule precedence and chooses to build
> "main.c".
>
> If you're saying that make is actually compiling 'main.cpp' into
> 'main.o' and it's using 'cc' as the compiler, I'd say that's not
> possible unless there is something else going on that you haven't
> described.
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]