Hi.
About 'fltk' demo programs, the 'Segmentation fault' is caused by a wrong linking process. All 'fltk' demo programs use the library 'libX11.so.6' and this library uses the nano-X library. But the nano-X library is generated as a static library i.e. 'libnano-X.a' in default configrations. This 'libnano-X.a' uses 'libc' and 'libc' is a shared library. So the generated code for the function 'GrSetErrorHandler' in libX11.so.6 is as follows.
00017328 <GrSetErrorHandler>:
17328: defffc04 addi sp,sp,-16
1732c: dc400015 stw r17,0(sp)
17330: 044000f4 movhi r17,3
17334: 8c63be04 addi r17,r17,-28936
17338: dd400215 stw r21,8(sp)
1733c: 202b883a mov r21,r4
17340: 8809883a mov r4,r17
17344: dfc00315 stw ra,12(sp)
17348: dcc00115 stw r19,4(sp)
1734c: 0008ac40 call 8ac4 <_init+0x408> <-----
17350: d4e29517 ldw r19,-30124(gp)
17354: 8809883a mov r4,r17
17358: d5629515 stw r21,-30124(gp)
1735c: 00087a00 call 87a0 <_init+0xe4> <-----
17360: 9805883a mov r2,r19
17364: dfc00317 ldw ra,12(sp)
17368: dd400217 ldw r21,8(sp)
1736c: dcc00117 ldw r19,4(sp)
17370: dc400017 ldw r17,0(sp)
17374: dec00404 addi sp,sp,16
17378: f800283a ret
When we execute this, the real code is as follows.
0x2aae3328: addi sp,sp,-16
0x2aae332c: stw r17,0(sp)
0x2aae3330: movhi r17,3
0x2aae3334: addi r17,r17,-28936
0x2aae3338: stw r21,8(sp)
0x2aae333c: mov r21,r4
0x2aae3340: mov r4,r17
0x2aae3344: stw ra,12(sp)
0x2aae3348: stw r19,4(sp)
0x2aae334c: call 0x20008ac4 <-----
0x2aae3350: ldw r19,-30124(gp)
0x2aae3354: mov r4,r17
0x2aae3358: stw r21,-30124(gp)
0x2aae335c: call 0x200087a0 <-----
0x2aae3360: mov r2,r19
0x2aae3364: ldw ra,12(sp)
0x2aae3368: ldw r21,8(sp)
0x2aae336c: ldw r19,4(sp)
0x2aae3370: ldw r17,0(sp)
0x2aae3374: addi sp,sp,16
0x2aae3378: ret
Of cource these relocations are wrong and the calling address '0x20008ac4' etc. will make 'Segmentation faults' .
The easy way to avoid this failure is to make the nano-X library as a shared library. Inside the config file '/home/**/nios2-linux/uClinux-dist/user/microwin/src/config', change
# #################################################################### # Libraries to build: microwin, nano-X, nanowidget, object frameworks# # ###################################################################
MICROWIN = Y
NANOX = Y
SHAREDLIBS = Y <---- Change this from N to Y
OBJFRAMEWORK = N
flush the contents of the directory ' /home/**/nios2-linux/uClinux-dist/user/microwin/src/lib' and libX11.so.6.2 in '/home/**/nios2-linux/uClinux-dist/user/microwin/nxlib/nxlib-0.45', we can get new 'libX11.so.6.2' by 'make'. After copying the new library with '
libnano-X.so' and 'libstdc++.so.6', we can evoke 'hello', 'clock' and 'editor' successfully. But 'valuator' will generate SEGV, when I touch its dials. Why?
Kazu