Dan.Allard Posted May 5, 2016 Posted May 5, 2016 How do I access the gplib library from linux? I am writing a program which will run in linux and be compiled by gcc on the PP in linux. I have looked at the software reference the users manual and at the help in the IDE but I can't seem to find any reference which shows an example of programming directly in linux on the PP. I have searched the PP directory structure some and haven't found any header files. I could run gpascii in the background but I would prefer to link to a dynamic library instead. It would be more efficient than running another program in the background.
shansen Posted May 5, 2016 Posted May 5, 2016 Dan, You can #include and then link your program against libbpmac.so. Structs for shared memory access are located in RtGpShm.h. You must call InitLibrary() from gplib.h to open the connection to the library's shared memory, and then CloseLibrary() when your program exits. The main pointer to gplib shared memory is "pshm" (defined in RtGpShm.h). See the Power PMAC User's Manual for more info.
Dan.Allard Posted May 5, 2016 Author Posted May 5, 2016 Thanks. For some reason the files don't seem to be on the path for the g++ compiler. I had to include the full path. The extern C is because I am programming in C++. extern "C" { #include "/opt/ppmac/ppmac/libppmac/gplib.h" } There is also a typo in the other file name above it should be. /opt/ppmac/libppmac/libppmac.so
Dan.Allard Posted May 6, 2016 Author Posted May 6, 2016 Getting closer but the compiler isn't happy. It looks like I am missing another include file. I will dig into the manual and IDE help tomorrow and see what I can come up with. This is the code from main.cpp extern "C" { #include } int main(int argc, const char * argv[]) { // opens the deltatau lib InitLibrary() This is what I got when my makefile ran showing the g++ flags and the result. g++ -g -Wall -c -I /opt/ppmac/libppmac/ -I /opt/ppmac/ppmac/rtpmac/ main.cpp In file included from /opt/ppmac/ppmac/rtpmac/RtGpShm.h:2250, from /opt/ppmac/libppmac/gplib.h:31, from main.cpp:14: /opt/ppmac/libppmac/rtpmacapi.h:404: error: use of enum ‘macrocomtype’ without previous declaration /opt/ppmac/libppmac/rtpmacapi.h:457: error: use of enum ‘macrostationtype’ without previous declaration /opt/ppmac/libppmac/rtpmacapi.h:472: error: use of enum ‘macrocomtype’ without previous declaration /opt/ppmac/libppmac/rtpmacapi.h:487: error: use of enum ‘macrocomtype’ without previous declaration /opt/ppmac/libppmac/rtpmacapi.h:513: error: use of enum ‘macrocomtype’ without previous declaration /opt/ppmac/libppmac/rtpmacapi.h:530: error: use of enum ‘macrocomtype’ without previous declaration /opt/ppmac/libppmac/rtpmacapi.h:554: error: use of enum ‘macrocomtype’ without previous declaration /opt/ppmac/libppmac/rtpmacapi.h:568: error: use of enum ‘macrocomtype’ without previous declaration In file included from /opt/ppmac/libppmac/gplib.h:43, from main.cpp:14: /opt/ppmac/libppmac/cmdprocessor.h:48: error: ‘MAX_MBSOCKETS’ was not declared in this scope
Dan.Allard Posted May 6, 2016 Author Posted May 6, 2016 I was just thinking there are a few of both header files on my system maybe I have the wrong pair? Which directory should I be linking to? 192.168.0.40:/# find -name gplib.h ./opt/ppmac/libppmac/gplib.h ./opt/ppmac/ppmac/libppmac/gplib.h ./var/ftp/ppmaclibs/libppmac/gplib.h ./.readonly/var/ftp/ppmaclibs/libppmac/gplib.h ./.readonly/var-tmpfs-mirror/ftp/ppmaclibs/libppmac/gplib.h root@192.168.0.200 192.168.0.40:/# find -name RtGpShm.h ./opt/ppmac/rtpmac/RtGpShm.h ./opt/ppmac/ppmac/rtpmac/RtGpShm.h ./var/ftp/ppmaclibs/rtpmac/RtGpShm.h ./.readonly/var/ftp/ppmaclibs/rtpmac/RtGpShm.h ./.readonly/var-tmpfs-mirror/ftp/ppmaclibs/rtpmac/RtGpShm.h root@192.168.0.200 192.168.0.40:/# find -name libppmac.so ./opt/ppmac/libppmac/libppmac.so ./opt/ppmac/ppmac/libppmac/libppmac.so ./var/ftp/ppmaclibs/libppmac/libppmac.so ./.readonly/var/ftp/ppmaclibs/libppmac/libppmac.so ./.readonly/var-tmpfs-mirror/ftp/ppmaclibs/libppmac/libppmac.so
Dan.Allard Posted May 6, 2016 Author Posted May 6, 2016 I found two versions of the headers files which match but I think I have something wrong with the link to the shared library in my make files because it gives me a list of undefined reference to errors when it links. This is my first time building make files by hand. At this point I think it is a problem with the g++ command line but I can't see what is wrong. make g++ -g -Wall -c -I /opt/ppmac/libppmac -I /opt/ppmac/rtpmac main.cpp g++ -g -Wall -c libHTML/HTML_elementBase.cpp g++ -g -Wall -c libHTML/body.cpp g++ -g -Wall -c libHTML/a.cpp g++ -g -Wall -c libHTML/img.cpp g++ -g -Wall -L /opt/ppmac/libppmac -o index.cgi main.o HTML_elementBase.o body.o a.o img.o -l:libppmac.so /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_shm_open' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutexattr_init' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_create' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_setsockopt' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_bind' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_sem_post' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_shutdown' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_recv' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_ftruncate' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_select' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_sem_open' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_setschedparam' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_ioctl' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_nanosleep' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_sem_wait' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_read' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_sem_close' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_socket' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutex_unlock' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutexattr_settype' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_sem_unlink' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_munmap' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutex_lock' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutex_destroy' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutex_init' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_listen' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutexattr_destroy' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_close' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_sched_yield' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_send' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_mmap' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_connect' /opt/ppmac/libppmac/libppmac.so: undefined reference to `__wrap_open' collect2: ld returned 1 exit status
Dan.Allard Posted May 6, 2016 Author Posted May 6, 2016 I tried linking to the library files in the other directory names this morning and got a very similar result but with slightly different error messages. make g++ -g -Wall -c -I /opt/ppmac/ppmac/libppmac -I /opt/ppmac/ppmac/rtpmac main.cpp g++ -g -Wall -c libHTML/HTML_elementBase.cpp g++ -g -Wall -c libHTML/body.cpp g++ -g -Wall -c libHTML/a.cpp g++ -g -Wall -c libHTML/img.cpp g++ -g -Wall -L /opt/ppmac/ppmac/libppmac -o index.cgi main.o HTML_elementBase.o body.o a.o img.o -l:libppmac.so /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `shm_open' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xnarch_tsc_to_ns' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_fault_stack' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_current_mode_key' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_init_current_mode' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_slow_get_current' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `shm_unlink' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_handle_mlock_alert' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_set_current' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_bind_skin_opt' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_slow_get_current_mode' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xnarch_divrem_billion' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_sem_heap' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `__xnsig_dispatch' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_sigshadow_install_once' /usr/local/xenomai/lib/libpthread_rt.so.1: undefined reference to `xeno_current_key' collect2: ld returned 1 exit status
Dan.Allard Posted May 6, 2016 Author Posted May 6, 2016 Just to complete the set here are the results from the /var/ftp directory. I will do some reading on the linker options and see if maybe i am missing something there. make g++ -g -Wall -c -I /var/ftp/ppmaclibs/libppmac -I /var/ftp/ppmaclibs/rtpmac main.cpp g++ -g -Wall -c libHTML/HTML_elementBase.cpp g++ -g -Wall -c libHTML/body.cpp g++ -g -Wall -c libHTML/a.cpp g++ -g -Wall -c libHTML/img.cpp g++ -g -Wall -L /var/ftp/ppmaclibs/libppmac -o index.cgi main.o HTML_elementBase.o body.o a.o img.o -l:libppmac.so /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_shm_open' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutexattr_init' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_create' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_setsockopt' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_bind' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_sem_post' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_shutdown' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_recv' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_ftruncate' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_select' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_sem_open' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_setschedparam' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_ioctl' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_nanosleep' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_sem_wait' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_read' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_sem_close' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_socket' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutex_unlock' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutexattr_settype' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_sem_unlink' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_munmap' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutex_lock' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutex_destroy' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutex_init' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_listen' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_pthread_mutexattr_destroy' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_close' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_sched_yield' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_send' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_mmap' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_connect' /var/ftp/ppmaclibs/libppmac/libppmac.so: undefined reference to `__wrap_open' collect2: ld returned 1 exit status make: *** [index.cgi] Error 1
daves Posted May 6, 2016 Posted May 6, 2016 Hi Dan, I am no expert in this but I can cross-compile my own C code on Windows to a .out file and run on the linux system. The key is the make file. I would first build (in Release config) and download a project from the IDE with a background c-app in it then take the makefile from the app's folder ("capp1_release.mak" or similar) and look at that for how to create your own. I run an administrator command prompt with "PATH=C:\DeltaTau\Power PMAC IDE\compilers\bin;C:\DeltaTau\Power PMAC IDE\compilers\usr\local\bin". Then I have, for example, the following: example.c #include int main(void) { struct timespec uSecSleeper = { 0 }; // Initialize time structure struct sched_param param; param.__sched_priority = 0; pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m); uSecSleeper.tv_nsec = 1000000; // 1e6 nanoseconds, which equals 1 msec InitLibrary(); while (1) { pshm->P[0]++; nanosleep(&uSecSleeper, NULL); } CloseLibrary(); return 0; } Then I rename the xxx_yyy.mak file to Makefile, put in a directory with your c file, make a subfolder called Release. Then change anything referencing "../../../Bin/Release/" to "Release/" in the makefile. Then make sure the bit defining the sources is [/code] SRCS = \ example.c OBJS = $(SRCS:.c=.o) PROG = "Release/example.out" Then cd your command prompt to wherever your files are and run make. Then you can FTP the example.out file to the PPMAC, change permissions and execute! Watch P0 go up! I have no idea if this is the full story but may help you modify your makefile... I imagine compiling C++ on the linux system has its own issues, I would be interested know how you get on. Dave
Dan.Allard Posted May 7, 2016 Author Posted May 7, 2016 Hi Dave, You had a good idea. I did some more research on the web and figured out the linker errors is a missing link to the exnomai library which is used by libppmac.so. There are a few shared libraries in the exnomai directory so through trial and error I determined which ones I need to get a simple program with just a library open and close function call to compile and run. the calls below from my makefile worked to produce an output file which will run. As an fyi this approach is not for the faint of heart. Several times the program compiled but something else was going off into left field when it would run until I got to the minimum list of included library files I got an error message when the program ran which which I have no idea what it meant. Until I hear otherwise I am going to assume the solution which compiles and runs must be acceptable. It would be nice to know what the error message below is all about. Also it would be good to know that just linking the libraries in with the compiler flags below is sufficient. I don't know if there are any special flags that should be used with the libraries. My hope is that any special flags would only have been needed when the libraries were compiled not at linking. My reasoning for this is simply that the linking is really just linking calls to functions with binary function code. error message which showed up when the program ran until I eliminated all the unneeded library links. Xenomai: uitron skin or CONFIG_XENO_OPT_PERVASIVE disabled. (modprobe xeno_uitron?) make: *** [default] Error 1 working makefile run make g++ -g -Wall -c -I /opt/ppmac/libppmac/ -I /opt/ppmac/rtpmac main.cpp g++ -g -Wall -c libHTML/HTML_elementBase.cpp g++ -g -Wall -c libHTML/body.cpp g++ -g -Wall -c libHTML/a.cpp g++ -g -Wall -c libHTML/img.cpp g++ -L /opt/ppmac/libppmac -L/usr/local/xenomai-2.5.6/lib -g -Wall main.o HTML_elementBase.o body.o a.o img.o -o index.cgi -l:libppmac.so -l:librtdk.so -l:libpthread_rt.so -l:librtdm.so -l:libxenomai.so
Recommended Posts