LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Problems compiling sigc++ programs (http://www.linuxquestions.org/questions/programming-9/problems-compiling-sigc-programs-246643/)

siminone 10-24-2004 06:05 AM

Problems compiling sigc++ programs
 
HI, apoplogies in advance if question is obvious, i'm new to linux programming.

I have been playing around with the Y Windows Demo and tried to compile a source file supplied with it.

Unfortunately, I errors and they were all to do with sigc++. Y Windows uses sigc++1.0 and there are test files supplied with it. I tried compiling these and I got errors. I used the following command to compile the test source file.

gcc hello_world.cc -I/usr/include/sigc++-1.0

I got the following errors


hello_world.cc:11: error: syntax error before `&' token
hello_world.cc: In function `void print(...)':
hello_world.cc:12: error: `cout' undeclared (first use this function)
hello_world.cc:12: error: (Each undeclared identifier is reported only once for each function it appears in.)
hello_world.cc:12: error: `str' undeclared (first use this function)
hello_world.cc: In function `int main()':
hello_world.cc:16: error: ISO C++ forbids declaration of `type name' with no type
hello_world.cc:16: error: syntax error before `&' token
hello_world.cc:18: error: `printer' undeclared (first use this function)
hello_world.cc:18: error: invalid conversion from `void (*)(...)' to `void (*)()'
hello_world.cc:18: error: initializing argument 1 of `SigC::Slot0<R> SigC::slot(R (*)()) [with R = void]'


The soucefile is as follows:

Code:

// Copyright 1999 Karl Nelson.

#include <iostream>
#include <string>
#include <sigc++/signal_system.h>

#ifdef SIGC_CXX_NAMESPACES
using namespace SigC;
#endif

void print(const string &str)
  {cout << str;}

main()
  {
  Signal1<void,const string &> printer;

  printer.connect(slot(print));

  printer("hello world\n");
  }

I have Mandrake 10.0 and using gcc 3.3.2. I hope I have supplyed enough details.

Thanks in advance

Alza

Mara 10-24-2004 09:15 AM

It's a C++ program, so compile with g++ instead of gcc.

siminone 10-24-2004 02:02 PM

I used g++ and it comes up with the same errors.

I am sure it is to do with using the lastest version of gcc and and older version of sigc++.

I've tried -std=c99 which I understand is the standard in which it is compiled in (which could be an earlier version of gcc?) but i get a warning and it does not work. I've checked the man file and can't find any flags that compile to that of previous versions.

Mara 10-24-2004 02:38 PM

One thing is to add 'using namespace std' somewhere at the beginning. Check if it helps.

siminone 10-24-2004 06:31 PM

thanks for help given Mara.

I managed to get it working with the following command which I got from the sigc++ site:

g++ example1.cc -o eg1 `pkg-config --cflags --libs sigc++-1.2`

The only problem now is figuring out how to compile the Y Win Source code file now I know Sigc++ isn't mucked up!!!


All times are GMT -5. The time now is 10:22 AM.