LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2013, 05:37 PM   #1
marbangens
Member
 
Registered: Aug 2012
Location: sweden
Distribution: Slackware, Fedora
Posts: 118

Rep: Reputation: Disabled
compiling amuc 1.7 error (help me understand and debug) error: taking address of temporary array


Hello all hackers
I'm running gcc version 4.7.2 20130108 [gcc-4_7-branch revision 195012] (SUSE Linux) and trying to build The Amsterdam Music Composer.
See link if you like:http://members.chello.nl/w.boeke/amuc/index.html

The code sample of the structure I think contains the problem is here:
Code:
struct MeterView {
  HSlider *meter;
  static const int meter_dim=6;
  Array<int,meter_dim> m;
  MeterView(Rect rect) {
    m=(int[meter_dim]){ 6,8,12,16,24,32 }; // here is a problem 
    meter=new HSlider(top_win,rect,MR,0,meter_dim-1,"meter",0,0,meter_cmd,cBackground);
    draw(app->act_meter);
  }
  void draw(int val) {
    int i=m.get_index(val);
    if (i>=0) {
      set_text(meter->text,"%d",val);
      meter->set_hsval(i,0);
      return;
    }
    alert("warning: non-standard meter value %d",val);
    set_text(meter->text,"%d",val);
    meter->set_hsval(-1,0);
  }
  static void meter_cmd(Id,int val,int,char*&,bool);
};

And the error:
Code:
make -C src-abcm2ps
make[1]: Entering directory `/home/marbangens/projects/amuc-1.7/src-abcm2ps'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/marbangens/projects/amuc-1.7/src-abcm2ps'
make -C src
make[1]: Entering directory `/home/marbangens/projects/amuc-1.7/src'
compiling amuc.cpp (g++)
amuc.cpp: In constructor ‘MeterView::MeterView(Rect)’:
amuc.cpp:616:41: error: taking address of temporary array
make[1]: *** [amuc.o] Error 1
make[1]: Leaving directory `/home/marbangens/projects/amuc-1.7/src'
make: *** [amuc] Error 2

Can someone explain to me what the problem might be? I would like to fix it myself if I can. I tried reading about arrays and googled about the error: taking address of temporary array; but I don't understand still.
Source code: http://members.chello.nl/w.boeke/amuc/amuc-1.7.tar.gz

Last edited by marbangens; 04-22-2013 at 05:41 PM.
 
Old 04-23-2013, 10:02 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
try this:

Code:
static const int tmparray[]= { 6,8,12,16,24,32 };
m=(int[meter_dim])tmparray;
 
Old 04-24-2013, 02:34 PM   #3
marbangens
Member
 
Registered: Aug 2012
Location: sweden
Distribution: Slackware, Fedora
Posts: 118

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
try this:

Code:
static const int tmparray[]= { 6,8,12,16,24,32 };
m=(int[meter_dim])tmparray;
That gave:
Code:
amuc.cpp:617:23: error: ISO C++ forbids casting to an array type ‘int [6]’
 
Old 04-24-2013, 03:58 PM   #4
marbangens
Member
 
Registered: Aug 2012
Location: sweden
Distribution: Slackware, Fedora
Posts: 118

Original Poster
Rep: Reputation: Disabled
This worked ;p
Code:
m[meter_dim]= 6,8,12,16,24,32 ;
Now I have an linking error..
Code:
linking amuc (g++)
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: amuc.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: note: 'pthread_create@@GLIBC_2.2.5' is defined in DSO /lib64/libpthread.so.0 so try adding it to the linker command line
/lib64/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make[1]: *** [amuc] Error 1
 
Old 04-24-2013, 07:37 PM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 4 .

Quote:
...... /lib64/libpthread.so.0 so try adding it to the linker command line
Please add -lpthread to "Makefile.inc" line 2 :
Code:
LDFLAGS= -lX11   -lasound   -lXft   -lcairo   -ljack  -lpthread
 
Old 04-25-2013, 09:54 AM   #6
marbangens
Member
 
Registered: Aug 2012
Location: sweden
Distribution: Slackware, Fedora
Posts: 118

Original Poster
Rep: Reputation: Disabled
Running amuc displays an error at start, it gos like this:
Code:
Array:index=8(>=8)
Warning: non-standard meter value 8
I can change the meter value to 6 but the other options only displays 0.
If a chose one of those 0 options then amuc crashes.
 
Old 04-25-2013, 10:20 AM   #7
marbangens
Member
 
Registered: Aug 2012
Location: sweden
Distribution: Slackware, Fedora
Posts: 118

Original Poster
Rep: Reputation: Disabled
This is a bit ugly but it solved the problem
Code:
  MeterView(Rect rect) {
    m[0]= 6;
    m[1]= 8;
    m[2]= 12;
    m[3]= 16;
    m[4]= 24;
    m[5]= 32;
    meter=new HSlider(top_win,rect,MR,0,meter_dim-1,"meter",0,0,meter_cmd,cBackground);
    draw(app->act_meter);
  }
I'm new to programming so this may be the "wrong way of doing it". Can anybody tell me how
it can be done a better way?
 
Old 04-25-2013, 11:28 AM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
A stand alone compilable version of the first post is
Code:
typedef unsigned int uint;

template <class T,uint dim>
struct Array {
    T buf[dim];
    uint len();
    uint get_index(T& memb);
    T& operator[](uint ind) {
        if (ind<dim) return buf[ind];
        // alert("Array: index=%d (>=%d)",ind,dim);// if (debug) abort();
        return buf[0];
    }
    void operator=(const T *val) { for (uint i=0;i<dim;++i) buf[i]=val[i]; }
};


struct MeterView {
    static const int meter_dim=6;
    Array<int,meter_dim> m;
    MeterView()
    {
        m=(int[meter_dim]){ 6,8,12,16,24,32 }; // here is a problem 
    }
};
If you don't mind depending on C++11 you can use an extended initializer list:
Code:
    MeterView() : m{{ 6,8,12,16,24,32 }} 
    {
    }
Although if you have C++11 you should also be using std::array instead of a custom Array class. A more backwards compatible solution is:
Code:
    MeterView()
    {
        int meters[meter_dim] = { 6,8,12,16,24,32 };
        m = meters;
    }
 
1 members found this post helpful.
Old 04-25-2013, 11:29 AM   #9
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 6, # 7.

I get no errors or warnings like that at starting 'amuc' in Suse 12.3 - 64bit.
( It says jackd not started, but the GUI opens OK.)

But then again I made no changes in any files to compile amuc.
'amuc-1.7' is an old application, year 2009, can be compiled with g++-4.4 .
( E.g. gcc44-c++-4.4.2 from "SLE 10 devel:gcc.repo".)
The 'amuc-1.7/src/Makefile' line 5 was edited from g++ to g++-4.4 .

-
 
  


Reply

Tags
amuc



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to understand cross compiling for ARM on x86, and why some distributions don't kodekata Linux - General 5 05-31-2012 03:30 PM
Compiling PECL ssh2 - debug 144419855310001 Programming 0 08-29-2007 10:14 AM
Compiling With Debug Info Does Not Work? spotmax777 Linux - General 0 07-18-2007 01:30 PM
i do not understand compiling at all... bookgekgom Linux - Software 2 12-29-2006 03:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration