Can't link the sdk to Ogre3D source

Post questions, comments and feedback to our 3Dconnexion UNIX and Linux Development Team.

Moderator: Moderators

Post Reply
Absum
Posts: 53
Joined: Tue Apr 24, 2007 4:00 am
Location: Sweden
Contact:

Can't link the sdk to Ogre3D source

Post by Absum »

I've been having some problem with getting the SDK into a Ogre3D application, when i've linked and included everything i get this when compiling:

Code: Select all

scons -Q
g++ -o bin/main.o -c -Iinclude -I/usr/include/OGRE -I/usr/include/OIS src/main.cpp
gcc -o include/xdrvlib.o -c include/xdrvlib.c
ar rc src/libxdrvlib.a include/xdrvlib.o
ranlib src/libxdrvlib.a
g++ -o bin/main bin/main.o -L. -lOgreMain -lOIS src/libxdrvlib.a
bin/main.o: In function `BaseFrameListener::setupSpaceNav(_XDisplay*, unsigned long)':
main.cpp:(.text._ZN17BaseFrameListener13setupSpaceNavEP9_XDisplaym[BaseFrameListener::setupSpaceNav(_XDisplay*, unsigned long)]+0x15): undefined reference to `MagellanInit(_XDisplay*, unsigned long)'
collect2: ld returned 1 exit status
scons: *** [bin/main] Error 1
This compile was made with a static library... but its the same error as with just a normal object. I use scons for building and the SConstruct file looks like this:

Code: Select all

platform = ARGUMENTS.get('OS', Platform())

listinc = [
	'include',
	'/usr/include/OGRE',
	'/usr/include/OIS',
	]

cflags=['']

env_ogre=Environment(CPPPATH=listinc, LIBPATH='.', CCFLAGS = cflags)
env_xdrv=Environment()

conf = Configure(env_ogre)
if not conf.CheckCXXHeader('Ogre.h'):
	print 'Ogre must be installed!'
	Exit(1)
if not conf.CheckCXXHeader('OISPrereqs.h'):
	print 'OIS must be installed!'
	Exit(1)
if not conf.CheckLib('OgreMain'):
	print 'OgreMain library must be in path'
	Exit(1)
if not conf.CheckLib('OIS'):
	print 'OIS library must be in path'
	Exit(1)

main_program_list=Split("""
	src/main.cpp
	""")

libs_list=Split("""
	OgreMain
	OIS
	""")

main_list = env_ogre.Object('bin/main.o', main_program_list, LIBS=libs_list, LIBPATH='.')
#xdrv_list = env_xdrv.Object('src/xdrvlib.o', 'include/xdrvlib.c', LIBS='X11')
xdrv_list = env_xdrv.Library('src/xdrvlib', 'include/xdrvlib.c', LIBS='X11')

env_ogre.Program(main_list, LIBS=libs_list+xdrv_list, LIBPATH='.')
Sorry if its too much text, i just really want this to work so I really need the help.
UtaSH
Moderator
Moderator
Posts: 3754
Joined: Mon Nov 27, 2006 10:34 am
Location: Munich, Germany
Contact:

Post by UtaSH »

Unfortunaetly I don't have any knowlegde about scons. :?
Does it make any difference if you compile the xdrvlib with g++ instead of gcc?
Absum
Posts: 53
Joined: Tue Apr 24, 2007 4:00 am
Location: Sweden
Contact:

Post by Absum »

No it makes no difference, atleast not when I compiled the xapp demo (made a scons script to compile it just to make sure it wasn't scons that did something funny)

Code: Select all

import os
env = Environment(ENV = os.environ, CC='gcc', CPPPATH=['/usr/include', '.'], CCFLAGS='')

xdrv_list = ['xdrvlib.c']

xapp_list = ['xapp.c']

xdrv = env.Object(xdrv_list, LIBS=['X11', 'm'])

env.Program(xapp_list + xdrv, LIBS=['X11', 'm'])
Absum
Posts: 53
Joined: Tue Apr 24, 2007 4:00 am
Location: Sweden
Contact:

Post by Absum »

I take that back when i compiled the demo with g++ instead it gave alot of errors.

Code: Select all

scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o xapp.o -c -I/usr/include -I. xapp.c
xapp.c:26: error: ‘argc’ was not declared in this scope
xapp.c:26: error: ‘argv’ was not declared in this scope
xapp.c:26: error: initializer expression list treated as compound expression
xapp.c:27: error: expected ‘,’ or ‘;’ before ‘int’
xapp.c:28: error: storage size of ‘argv’ isn't known
xapp.c:29: error: expected unqualified-id before ‘{’ token
scons: *** [xapp.o] Error 1
scons: building terminated because of errors.
Absum
Posts: 53
Joined: Tue Apr 24, 2007 4:00 am
Location: Sweden
Contact:

Post by Absum »

As far as i've seen xdrvlib has to be compiled with gcc or it just gives alot of errors and will not compile. Could the problem possibly be that i try to write c++ applications when the sdk is in c?
Absum
Posts: 53
Joined: Tue Apr 24, 2007 4:00 am
Location: Sweden
Contact:

Post by Absum »

Damn, not often i have right about this stuff :P

Added:

Code: Select all

#ifdef __cplusplus
extern "C"
{
#endif

[...]

#ifdef __cplusplus
}
#endif
to the sdk headers and now it compiles without a hitch. Yey!
UtaSH
Moderator
Moderator
Posts: 3754
Joined: Mon Nov 27, 2006 10:34 am
Location: Munich, Germany
Contact:

Post by UtaSH »

Aah! That did the trick. Sorry for not pointing this out earlier. From your message I wasn't aware that this code was missing in your project. Thanks for posting this information here!

The error you posted above is because the xdrvlib.c is Kernighan/Ritchie style and g++ doesn't like this. Change the function header to ANSI C and the compiler will be happy. :) We will review the SDK concerning this.
skyechraebs
Posts: 12
Joined: Mon Jan 16, 2012 2:40 pm
Location: Zurich

Post by skyechraebs »

Thank's a lot for this thread. Had a long time considering how to use the 3dMouse in my C++ Qt project on Ubuntu..

Adding the lines
#ifdef linux
#define ParameterCheck
#endif
and putting it into
#ifdef __cplusplus
extern "C"
{
#endif

[...]

#ifdef __cplusplus
}
#endif
into the library header helped me running the xapp example =)
Post Reply