LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices



Reply
 
Search this Thread
Old 02-15-2007, 02:56 AM   #1
Tomtherab
LQ Newbie
 
Registered: Feb 2007
Posts: 15

Rep: Reputation: 0
Problems with compiling Objective-C using gcc in Slack 11.


I am currently porting a 3d engine to linux from the Mac. It of course uses some objective c. I've installed all the required libraries, and everything compiles fine except the objective c code.

As a test I've tried to compile this hello.m file:
#include <iostream>
#include <objc/objc.h>
#include <objc/Object.h>

int main (void) {
std::cout << "Hello." << std::endl;
return 0;
}

With:
bash-3.1$ g++ -c hello.m -o hello.o

It gives this error:
hello.m:1:20: iostream: No such file or directory
hello.m: In function `main':
hello.m:6: error: syntax error before ':' token

Next I tried this code:
#include <iostream>
#include <objc/objc.h>
#include <objc/Object.h>

using namespace std;

int main (void) {
cout << "Hello." << endl;
return 0;
}

With this command:
bash-3.1$ g++ -c Hello.m -o Hello.o

It produced this error:
hello.m:1:20: iostream: No such file or directory
hello.m:5: error: syntax error before "namespace"
hello.m:5: warning: data definition has no type or storage class
hello.m: In function `main':
hello.m:8: error: `cout' undeclared (first use in this function)
hello.m:8: error: (Each undeclared identifier is reported only once
hello.m:8: error: for each function it appears in.)
hello.m:8: error: `endl' undeclared (first use in this function)

Retrying the first file with the include path appended produced this:
bash-3.1$ g++ -c -I/usr/include/c++/3.4.6 hello.m -o hello.o
In file included from hello.m:1:
/usr/include/c++/3.4.6/iostream:44:28: bits/c++config.h: No such file or directory
In file included from /usr/include/c++/3.4.6/ios:44,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/c++/3.4.6/iosfwd:46:29: bits/c++locale.h: No such file or directory
/usr/include/c++/3.4.6/iosfwd:47:25: bits/c++io.h: No such file or directory
In file included from /usr/include/c++/3.4.6/iosfwd:48,
from /usr/include/c++/3.4.6/ios:44,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/c++/3.4.6/cctype:66: error: syntax error before "std"
/usr/include/c++/3.4.6/cctype:67: error: syntax error before '{' token
In file included from /usr/include/c++/3.4.6/iosfwd:49,
from /usr/include/c++/3.4.6/ios:44,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:

***[SNIP}***

In file included from /usr/include/stdlib.h:433,
from /usr/include/c++/3.4.6/cstdlib:52,
from /usr/include/c++/3.4.6/bits/stl_algobase.h:67,
from /usr/include/c++/3.4.6/bits/char_traits.h:46,
from /usr/include/c++/3.4.6/ios:46,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/sys/types.h:235: error: storage class specified for parameter `fsblkcnt_t'
/usr/include/sys/types.h:239: error: storage class specified for parameter `fsfilcnt_t'
In file included from /usr/include/sys/types.h:266,
from /usr/include/stdlib.h:433,
from /usr/include/c++/3.4.6/cstdlib:52,
from /usr/include/c++/3.4.6/bits/stl_algobase.h:67,
from /usr/include/c++/3.4.6/bits/char_traits.h:46,
from /usr/include/c++/3.4.6/ios:46,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/bits/pthreadtypes.h:35: error: storage class specified for parameter `_pthread_descr'
/usr/include/bits/pthreadtypes.h:52: error: storage class specified for parameter `pthread_attr_t'
/usr/include/bits/pthreadtypes.h:58: error: syntax error before "__extension__"
/usr/include/bits/pthreadtypes.h:66: error: syntax error before "_pthread_descr"
/usr/include/bits/pthreadtypes.h:68: error: `__pthread_cond_align_t' undeclared (first use in this function)
/usr/include/bits/pthreadtypes.h:68: error: (Each undeclared identifier is reported only once
/usr/include/bits/pthreadtypes.h:68: error: for each function it appears in.)
/usr/include/bits/pthreadtypes.h:68: confused by earlier errors, bailing out

I tried then adding the bits dir to the command:
bash-3.1$ g++ -c -I/usr/include/c++/3.4.6 -I/usr/include/c++/3.4.6/bits hello.m -o hello.o
In file included from hello.m:1:
/usr/include/c++/3.4.6/iostream:44:28: bits/c++config.h: No such file or directory
In file included from /usr/include/c++/3.4.6/ios:44,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/c++/3.4.6/iosfwd:46:29: bits/c++locale.h: No such file or directory
/usr/include/c++/3.4.6/iosfwd:47:25: bits/c++io.h: No such file or directory
In file included from /usr/include/c++/3.4.6/iosfwd:48,
from /usr/include/c++/3.4.6/ios:44,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/c++/3.4.6/cctype:66: error: syntax error before "std"
/usr/include/c++/3.4.6/cctype:67: error: syntax error before '{' token
In file included from /usr/include/c++/3.4.6/iosfwd:49,
from /usr/include/c++/3.4.6/ios:44,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/c++/3.4.6/bits/stringfwd.h:47: error: syntax error before '{' token
/usr/include/c++/3.4.6/bits/stringfwd.h:51: error: syntax error before '<' token
/usr/include/c++/3.4.6/bits/stringfwd.h:54: error: syntax error before '<' token
/usr/include/c++/3.4.6/bits/stringfwd.h:58: error: syntax error before '<' token
/usr/include/c++/3.4.6/bits/stringfwd.h:60: error: syntax error before '<' token
In file included from /usr/include/c++/3.4.6/cwchar:50,
from /usr/include/c++/3.4.6/bits/postypes.h:46,
from /usr/include/c++/3.4.6/iosfwd:50,
from /usr/include/c++/3.4.6/ios:44,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:

***[SNIP]***

In file included from /usr/include/stdlib.h:433,
from /usr/include/c++/3.4.6/cstdlib:52,
from /usr/include/c++/3.4.6/bits/stl_algobase.h:67,
from /usr/include/c++/3.4.6/bits/char_traits.h:46,
from /usr/include/c++/3.4.6/ios:46,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/sys/types.h:235: error: storage class specified for parameter `fsblkcnt_t'
/usr/include/sys/types.h:239: error: storage class specified for parameter `fsfilcnt_t'
In file included from /usr/include/sys/types.h:266,
from /usr/include/stdlib.h:433,
from /usr/include/c++/3.4.6/cstdlib:52,
from /usr/include/c++/3.4.6/bits/stl_algobase.h:67,
from /usr/include/c++/3.4.6/bits/char_traits.h:46,
from /usr/include/c++/3.4.6/ios:46,
from /usr/include/c++/3.4.6/ostream:45,
from /usr/include/c++/3.4.6/iostream:45,
from hello.m:1:
/usr/include/bits/pthreadtypes.h:35: error: storage class specified for parameter `_pthread_descr'
/usr/include/bits/pthreadtypes.h:52: error: storage class specified for parameter `pthread_attr_t'
/usr/include/bits/pthreadtypes.h:58: error: syntax error before "__extension__"
/usr/include/bits/pthreadtypes.h:66: error: syntax error before "_pthread_descr"
/usr/include/bits/pthreadtypes.h:68: error: `__pthread_cond_align_t' undeclared (first use in this function)
/usr/include/bits/pthreadtypes.h:68: error: (Each undeclared identifier is reported only once
/usr/include/bits/pthreadtypes.h:68: error: for each function it appears in.)
/usr/include/bits/pthreadtypes.h:68: confused by earlier errors, bailing out

I then renamed the hello.m files to hello.cpp files and they compiled just fine with the original g++ command:
i.e. g++ -c hello.cpp -o hello.o

I've read the section in the gcc manual about the steps required to compile objective-c, and I don't believe I've missed a step.

Also, I have searched google, as wel as these forums for the same problem but did not reach joy.

I had the feeling that perhaps my setup was wonky, so I tried to compile the same program on my wife's computer (Also Slack 11) with the identical result.

I'm thinking about trying slack-current to see if it's a problem with Slack 11, but I wanted to get a few suggestions before bailing out. I'll probably keep trying for a few days to see if I can learn something, but unfortunately I can't spend forever on this problem, especially because I've recently committed my work to svn and everyone knows the only thing left to do is get those 2 Objective C files to build.

If I have been unclear or should have included additional info, please let me know.
 
Old 02-15-2007, 03:46 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,775

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
You are trying to compile obj-c code with the C++(g++) compiler. You need to use gcc-objc compiler.
 
Old 02-15-2007, 05:48 AM   #3
Tomtherab
LQ Newbie
 
Registered: Feb 2007
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for the info regarding what compiler I need to use.

Is gcc-objc a seperate compiler or part of the GNC gcc package because I'm having a hard time getting any concrete info on where exactly I can get a slack package for this.

I've tried the following:

Reinstalled gcc-objc from the CD, as root:
# installpkg gcc-objc-3.4.6-i486-1.tgz

This doesn't result in an executable called gcc-objc anywhere. My attempt to find it resulted in this:
# find / -name "*gcc*"
/var/log/packages/gcc-objc-3.4.6-i486-1
/var/log/scripts/gcc-objc-3.4.6-i486-1
/mnt/cdrom/slackware/d/gcc-objc-3.4.6-i486-1.tgz.asc
/mnt/cdrom/slackware/d/gcc-objc-3.4.6-i486-1.tgz
/mnt/cdrom/slackware/d/gcc-objc-3.4.6-i486-1.txt
#

I also dicovered this bit of info in the from:
http://wiki.gnustep.org/index.php/Platform:Linux

"Slackware

Version 10.2

Libraries and accompanying applications will build with no modifications. Slackware 10.2 ships with GCC 3.3.6, so mixed Objective-C and C++ code is not supported, meaning additional frameworks/libraries may not be supported.

Version 11.0

This version of Slackware works the same as the previous (10.2). Libraries and applications will build with no modifications, but due to the GCC version used (3.4.6) Objective-C++ is not supported."

So, I'm assuming you have downloaded and installed gcc from gnu.org, because I can't seem to resolve this issue using the resources abailable from slackware.

I tried to get the slackware/current gcc package from the new PB site. but connectivity is nil for me right now.

I've been through the gcc manual regarding objective c several times and there is no mention of gcc-objc.

The only command line info I can find in the entire gcc manual is this single entry:
"This section describes the command-line options that are only meaningful for Objective-C programs, but you can also use most of the GNU compiler options regardless of what language your program is in. For example, you might compile a file some_class.m like this:

gcc -g -fgnu-runtime -O -c some_class.m"

On my system this produces the expected result:
$ gcc -g -fgnu-runtime -O -c hello.m
hello.m:1:20: iostream: No such file or directory
hello.m: In function `main':
hello.m:6: error: syntax error before ':' token

I guess the bottom line is this:
Do you know where I can find a slack package for this, or if the packages in rpm format on Fedora/mandrake would work?
 
Old 02-15-2007, 10:01 AM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,775

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
Sorry, I wasn't aware of those changes and quirks, since I've never used obj-C. However, you shouldn't have any trouble using an older compiler on your current Slackware, except that it will install over your current one.
I keep several compiler available on my system, since I do compile lots of older code and cross-compile, etc. What I would suggest you do is recompile an whichever older version of GCC you need for that (3.2.3?) including gcc-objc so that it installs to some other prefix than /usr. That way you can have it around without it interfering with your regular GCC.
I have build scripts which do this for gcc-2.95.3, 3.1, 3.2.3 and 3.3.6 and include a wrapper which sets up your environment for easy use. You'll just need to add objc to the list of languages, since I all ever compile is gcc and g++.
You can find those materialy here:
http://distro.ibiblio.org/pub/linux/...es/DevelTools/
Be sure to place the wrapper in your path somewhere and make it executable. then to use the compiler just type:
'GCC323 make'
 
Old 02-15-2007, 06:08 PM   #5
Tomtherab
LQ Newbie
 
Registered: Feb 2007
Posts: 15

Original Poster
Rep: Reputation: 0
Awesome! Okay, I'll see which version is that last to include gcc-objc and install that to /usr/local/gcc-x.x.x or maybe in /opt

Thanks so much for clearing that up. I'll definately give it a whirl and report my results here.

If this works, I'll owe you a first-born or something.

*skips off like a smurf*
 
Old 02-15-2007, 06:54 PM   #6
Tomtherab
LQ Newbie
 
Registered: Feb 2007
Posts: 15

Original Poster
Rep: Reputation: 0
I've been reading about newer versions of gcc as well, and discovered this in the changelog for 4.1, available here:
http://gcc.gnu.org/gcc-4.1/changes.html

"Objective-C++

* A new language front end for Objective-C++ has been added. This language allows users to mix the object oriented features of Objective-C with those of C++."

I will also intall this new version in /usr/local/gcc-4.1 and let you know if it is able to compile those mixed c++/obj-c source files.

I will also install 3.2.x and let you know if gcc-objc works too.
 
Old 02-15-2007, 10:31 PM   #7
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
You should be careful with gcc-4.x, a good number of programs simply fail to compile with it and/or throw errors when they really should have been warnings. That's just my experience with gcc-4.x on FC5. Usually they can be fixed, but code must be updated.
 
Old 02-16-2007, 07:54 PM   #8
Tomtherab
LQ Newbie
 
Registered: Feb 2007
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for the cautionary notes, TexMex, I was careful and installed gcc-4.1 into /usr/local keeping 3.2.4 as the system version. I hope to avoid problems that way.

Im terms of capability, this version of gcc had the following results with a few test programs:

C/Obj-C -- .m files, Success
C/Obj-C++ -- .mm files Success
C++/Obj-C -- .m files Failed
C++/OBj-C++ .mm files Success

These were hardly exhaustive tests, but I was able to finish porting over that Mac 3d engine, so I am confident to report that at least mixed c++ and obj-c++ work reliably together in my experience.

NB: When compiling, observe that passing --enable-languages=all to configure isn't sufficient. In order to get obj-c++ I passed:
--enable-languages=c,c++,fortran,java,objc,obj-c++

Last edited by Tomtherab; 11-16-2007 at 05:03 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
gcc compiling problems Jonas Brannstrom Programming 3 08-02-2005 04:12 PM
Problems compiling gcc. sombre1 Linux - Software 3 07-17-2005 06:28 PM
compiling problems with gcc 3.4 1337 Twinkie Linux - Software 1 05-13-2005 04:51 PM
GCC 3.2.2 - problems compiling MeinVerstand Linux - General 0 05-25-2004 02:24 PM
Slack 9.1 - Anyone else had gcc problems? jharris Slackware 3 10-18-2003 07:47 PM


All times are GMT -5. The time now is 04:43 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration