C++. Simple sample. Panda statically linked. Compile error.

Hello there!

I’m new to panda3d and still trying to run things out.

I was able to compile the SDK 1.8.0 source using:

python2 makepanda/makepanda.py --everything --no-python --no-pview --no-pandatool

with:

LINK_ALL_STATIC=True

.

Now I’m trying to compile this simple sample:

#include "pandaFramework.h"
#include "pandaSystem.h"

PandaFramework framework;
 
int main(int argc, char *argv[])
  {
    framework.open_framework(argc, argv);
    framework.set_window_title("My Panda3D Window");
    WindowFramework *window = framework.open_window();
    framework.main_loop();
    framework.close_framework();
    return (0);
  }

with:

g++ -c main.cpp -o main.o -I/myPathTo/built/include/
g++ main.o -o main -L/myPathTo/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub

but failing at:
http://pastebin.com/W1Z4mvwJ

Anyone else working with panda3d linked statically have encountered the same issue?
Or am I missing something obvious?

Adding -lpthread returned about 30% less errors:

g++ -c main.cpp -o main.o -I/myPathTo/built/include/ 
g++ main.o -o main -L/myPathTo/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread

Output: http://pastebin.com/j23sWmrp

Guess it’s some progress.

Recompiled the SDK 1.8.0 with:

python2 makepanda/makepanda.py --static --everything --no-python --no-pview --no-pandatool --no-nvidiacg

Trying to compile the sample with:

g++ -c main.cpp -o main.o -I/home/user/s_save/built/include/
g++ main.o -o main -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread

Output:http://pastebin.com/7CdMY91L

Still no luck.

Some improvement I guess.
Recompiled again the SDK 1.8.0 with:

python2 makepanda/makepanda.py --static --nothing --no-python --no-pview --no-pandatool --no-nvidiacg

Then tryed to compile the sample with:

g++ -c main.cpp -o main.o -I/home/user/s_save/built/include/
g++ main.o -o main -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread

Got this output (http://pastebin.com/tUcu7iRK):

[user@pc s_save]$ g++ -c main.cpp -o main.o -I/home/user/s_save/built/include/
[user@pc s_save]$ g++ main.o -o main -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread
/home/user/s_save/built/lib//libp3framework.a(p3framework_composite1.o): In function `PandaFramework::open_framework(int&, char**&)':
p3framework_composite1.cxx:(.text+0x6596): undefined reference to `init_libpandaegg()'
/home/user/s_save/built/lib//libp3dtool.a(p3dtoolutil_composite1.o): In function `unload_dso(void*)':
p3dtoolutil_composite1.cxx:(.text+0x23b7): undefined reference to `dlclose'
/home/user/s_save/built/lib//libp3dtool.a(p3dtoolutil_composite1.o): In function `load_dso_error()':
p3dtoolutil_composite1.cxx:(.text+0x23eb): undefined reference to `dlerror'
/home/user/s_save/built/lib//libp3dtool.a(p3dtoolutil_composite1.o): In function `get_dso_symbol(void*, std::string const&)':
p3dtoolutil_composite1.cxx:(.text+0x2471): undefined reference to `dlsym'
/home/user/s_save/built/lib//libp3dtool.a(p3dtoolutil_composite1.o): In function `load_dso(DSearchPath const&, Filename const&)':
p3dtoolutil_composite1.cxx:(.text+0x92df): undefined reference to `dlopen'
collect2: error: ld returned 1 exit status
[user@pc s_save]$

Any ideas? I’m probably missing something very obvious.

Added:

-lpandaegg -lp3glstuff

But still no luck.
Output: http://pastebin.com/pHSZBPU6

Adding:

-ldl

Solved the first part, now with:
http://pastebin.com/4Fapfb3u

Why not link to the libraries that the manual tells you to link to?

g++ filename.o -o filename -fPIC -L{panda3dlibs} -lp3framework -lpanda
     -lpandafx -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lp3direct

Although since you’ve compiled without Python support, you may be able to omit p3pystub.

rdb, thank you for the reply.

I tried what you said (like the manual):

[user@pc s_save]$ g++ -c main.cpp -o main.o -fPIC -O2 -I/home/user/s_save/built/include/
[user@pc s_save]$ g++ main.o -o main -fPIC -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandafx -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lp3direct
/usr/bin/ld: cannot find -lpandafx
/usr/bin/ld: cannot find -lp3direct
collect2: error: ld returned 1 exit status
[user@pc s_save]$ 

Since there aren’t any libpandafx and libp3direct (they where indeed not compiled), I removed those and tried:

g++ main.o -o main -fPIC -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub

That failed requesting pthreads.
So I added it:

g++ main.o -o main -fPIC -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread

That returned:

[user@pc s_save]$ g++ main.o -o main -fPIC -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread
/home/user/s_save/built/lib//libp3framework.a(p3framework_composite1.o): In function `PandaFramework::open_framework(int&, char**&)':
p3framework_composite1.cxx:(.text+0x6596): undefined reference to `init_libpandaegg()'
/home/user/s_save/built/lib//libp3dtool.a(p3dtoolutil_composite1.o): In function `unload_dso(void*)':
p3dtoolutil_composite1.cxx:(.text+0x23b7): undefined reference to `dlclose'
/home/user/s_save/built/lib//libp3dtool.a(p3dtoolutil_composite1.o): In function `load_dso_error()':
p3dtoolutil_composite1.cxx:(.text+0x23eb): undefined reference to `dlerror'
/home/user/s_save/built/lib//libp3dtool.a(p3dtoolutil_composite1.o): In function `get_dso_symbol(void*, std::string const&)':
p3dtoolutil_composite1.cxx:(.text+0x2471): undefined reference to `dlsym'
/home/user/s_save/built/lib//libp3dtool.a(p3dtoolutil_composite1.o): In function `load_dso(DSearchPath const&, Filename const&)':
p3dtoolutil_composite1.cxx:(.text+0x92df): undefined reference to `dlopen'
collect2: error: ld returned 1 exit status
[user@pc s_save]$ 

So I added libdl:

g++ main.o -o main -fPIC -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread -ldl

That returned:

[user@pc s_save]$ g++ main.o -o main -fPIC -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread -ldl
/home/user/s_save/built/lib//libp3framework.a(p3framework_composite1.o): In function `PandaFramework::open_framework(int&, char**&)':
p3framework_composite1.cxx:(.text+0x6596): undefined reference to `init_libpandaegg()'
collect2: error: ld returned 1 exit status
[user@pc s_save]$ 

So I added libpandaegg:

g++ main.o -o main -fPIC -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpthread -ldl -lpandaegg

But failed too. Output: http://pastebin.com/sF9tGkEP
I removed libp3pystub but didn’t change anything (at least on the output).

Edit: I compiled 'em as static. Guess the manual is using 'em as dynamic. Which leads me to believe, since I’ve had to add libpthread and libdl that are dynamic, that I’m probably missing something on g++ to mix static libs and dynamic libs.

Edit2: It can be done (http://gcc.gnu.org/ml/gcc/2001-07/msg01447.html), but didn’t solved the problem:

 g++ main.o -o main -Wl,-Bstatic -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lpandaegg -Wl,-Bdynamic -lpthread -ldl

Same output: http://pastebin.com/ydBAsJbX

The guys on #gcc @ freenode told me that the g++ line was ok, but:

Which, indeed, worked adding -lpanda after -lpandaegg:

[user@pc s_save]$ g++ -c main.cpp -o main.o -I/home/user/s_save/built/include/
[user@pc s_save]$ g++ -Wall main.o -o main -Wl,-Bstatic -L/home/user/s_save/built/lib/ -lp3framework -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3glstuff -lp3pystub -lpandaegg -lpanda -Wl,-Bdynamic -lpthread -ldl
[user@pc s_save]$ ./main 
Segmentation fault
[user@pc s_save]$ 

But now I have a Segmentation fault to figure out.
Oh well.

I’m still bashing my head against this.
Installed Ubuntu 12.04 (GCC 4.6) to give it a try.
No improvement unfortunately :frowning:

user@mac:~/t_tower$ g++ -c main.cpp -o main.o -I/home/user/t_tower/built/include/
user@mac:~/t_tower$ g++ -Wall main.o -o main -Wl,-Bstatic -L/home/user/t_tower/built/lib/ -lp3framework -lpandaegg -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3glstuff -Wl,-Bdynamic -lpthread -ldl 
user@mac:~/t_tower$ ./main 
Segmentation fault
user@mac:~/t_tower$

Gotta question, does this sample have anything wrong?

user@mac:~/t_tower$ cat main.cpp 
#include "pandaFramework.h"
#include "pandaSystem.h"

PandaFramework framework;
 
int main(int argc, char *argv[])
  {
    framework.open_framework(argc, argv);
    framework.set_window_title("My Panda3D Window");
    WindowFramework *window = framework.open_window();

    framework.main_loop();
    framework.close_framework();
    return (0);
  }
user@mac:~/t_tower$

.

Sorry, I can’t see anything wrong with it and it runs well on my linux box. Here’s my setup:
Ubuntu 10.10 (maverick)
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5.1) 4.4.5
panda3d1.7_1.7.2~maverick_i386.deb

$g++ -c main.cpp -o main.o -fPIC -O2 -I/usr/include/python2.6/ -I/usr/include/panda3d/ 
$g++ main.o -o main -fPIC -L/usr/lib/panda3d/ -lp3framework -lpanda -lpandafx -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lp3direct 
$./main 
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)

dri, thank you for the reply.

Forgive me for asking, but are you using panda3d statically compiled?

You are right, my reply was off topic. Sorry about that :blush:

dri, no problem at all.

I’m looking at gdb trying to figure this out :confused:

user@mac:~/t_tower$ g++ -g -static-libgcc -pthread main.cpp -I/home/user/t_tower/built/include/ -L/home/user/t_tower/built/lib/ -lp3framework -lpandaegg -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -ldl
user@mac:~/t_tower$ ./a.out 
Segmentation fault
user@mac:~/t_tower$ gdb a.out
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/user/t_tower/a.out...done.
(gdb) r
Starting program: /home/user/t_tower/a.out 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
 
Program received signal SIGSEGV, Segmentation fault.
0x08446fd7 in std::_Deque_base<ConstPointerTo<Event>, pallocator_array<ConstPointerTo<Event> > >::_M_initialize_map(unsigned int) ()
(gdb) bt
#0  0x08446fd7 in std::_Deque_base<ConstPointerTo<Event>, pallocator_array<ConstPointerTo<Event> > >::_M_initialize_map(unsigned int)
    ()
#1  0x08442de1 in EventQueue::EventQueue() ()
#2  0x08442e7c in EventQueue::make_global_event_queue() ()
#3  0x08442f25 in EventHandler::make_global_event_handler() ()
#4  0x080a1545 in PandaFramework::PandaFramework() ()
#5  0x08093412 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at main.cpp:4
#6  0x0809354b in _GLOBAL__sub_I_framework () at main.cpp:15
#7  0x08713752 in __libc_csu_init ()
#8  0xb7d0d46a in __libc_start_main () from /lib/i386-linux-gnu/libc.so.6
#9  0x080931f1 in _start ()
(gdb) Quit
A debugging session is active.
 
        Inferior 1 [process 17910] will be killed.
 
Quit anyway? (y or n) y
user@mac:~/t_tower$ 

Output: ideone.com/AsJ63

EDIT: played a bit over the test sample and moving

PandaFramework framework;

to inside the main function actually voided the segmentation fault.

user@mac:~/t_tower$ cat main.cpp 
#include "pandaFramework.h"
#include "pandaSystem.h"

int main(int argc, char *argv[])
  {
    PandaFramework framework;

    framework.open_framework(argc, argv);
    framework.set_window_title("My Panda3D Window");
    WindowFramework *window = framework.open_window();

    framework.main_loop();
    framework.close_framework();

    return (0);
  }
user@mac:~/t_tower$ g++ -g -static-libgcc -pthread main.cpp -I/home/user/t_tower/built/include/ -L/home/user/t_tower/built/lib/ -lp3framework -lpandaegg -lpanda -lpandaexpress -lp3dtoolconfig -lp3dtool -ldl
user@mac:~/t_tower$ ./a.out 
Warning: unable to auto-locate config files in directory named by "<auto>etc".
Known pipe types:
(all display modules loaded.)
No graphics pipe is available!
Your Config.prc file must name at least one valid panda display
library via load-display or aux-display.
^C
user@mac:~/t_tower$ 

Output: http://ideone.com/WzWlD

If this sounds like a terrible idea, please, let me know.

EDIT 2: Recompiled the source with opengl support. Now trying to figure out libs dependency hierarchy for -lp3glstuff and -lpandagl. No luck so farm.

Sorry guys, I’m giving up. It’s been almost two weeks and I’m still trying to get a working sample statically.

The c++ documentation gap is too wide and the code base is far from simple.

Moving to Irrlicht (compiled all statically and assembled a working sample in 1h tops, very well documented too).

Thanks for the replies and good luck.

.

.

Actually, that’s a very good point. The PandaFramework constructor calls into AsyncTaskManager::get_global_ptr(), which returns a static member that is not guaranteed to be initialised before the PandaFramework is due to the fact that it’s a PointerTo object and not a simple C datatype.

Good find, I’ll put it on the list! For now, the workaround would be not to create the PandaFramework object at static init time.

OK, I fixed the AsyncTaskManager issue, but looking at vasco’s traceback earlier, it seems that EventQueue also causes a static init issue. I’m not sure what the problem is there, it seems to be something different from the task manager issue. Perhaps someone with more intimate knowledge of C++ allocators and such could help out here.

For now, it’s clear that creating a PandaFramework at static init time should be avoided.