Webserver demo to c plus plus

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Webserver demo to c plus plus

Jump to solution
1,536 Views
leepenn
Contributor III

Hi all,

     Have an application I have to convert to c++ compiler due to GCC and PEG. We are using CW 10.6 and MQX 4.1. Have made the changes to MQX Libraries and code seems to work all but webserver, have added C++ ifdef to the ipcfg.h, httpsrv.h, and httpsrv_supp.h, and I am getting undefined reference to `cgi_lnk_tbl'. I have imported the cplus example moved the code from the http server example and get the same error, C:/Freescale/APM_4_1/rtcs/examples/httpsrv/httpdsrv.c:249: undefined reference to `cgi_lnk_tbl'.

     Not sure where to look as when I click go to reference it goes right to the struct definition in the rtcs library.

Thanks

Lee


Labels (1)
Tags (3)
0 Kudos
1 Solution
821 Views
leepenn
Contributor III


Kenny,

By combining the CGI.c into the RTCS.c the project compiled properly having them separate did not work. Thanks for the help!

View solution in original post

0 Kudos
7 Replies
821 Views
leepenn
Contributor III

Thanks all for your ideas. We have PEG working and other code in our workspace, but only can't seem to get webserver to compile when enabled. This only became an issue as we switched to MQX 4.1 to resolve not loading and memory issues with the MQX 4.0 webserver. Then when we switched we to 4.1 we had to switch to GCC then unfortunately PEG told support was lacking and last information we got from them was we had to switch everything to c++. We haven't be able to test everything fully but the only thing we cannot seem to compile is the RTCS enabled code. although when we disable the webserver, the workspace compiles and display comes up fine.

Not sure what to try yet with CW10.6 workspace as changing Linking order did not help, but we do have IAR on order.

0 Kudos
821 Views
leepenn
Contributor III

Hey guys,

    Thanks for the feedback, I am definitely including the cgi.c file and have all the files in the linker needed being described, see below for full messages. Kenny I tried with adding yours, but when you open the MQXNetwork.h file it says syntax error although it does not give a warning or error when compiling. I also added the files with my minor changes to get rid of cpp warnings.

**** Build of configuration Int Flash SramData Debug for project cplus_APM_4_1 ****

"C:\\Freescale\\CW MCU v10.6\\gnu\\bin\\mingw32-make" -j1 all
'Building file: C:/Freescale/APM_4_1/rtcs/examples/httpsrv/cgi.c'
'Executing target #1 C:/Freescale/APM_4_1/rtcs/examples/httpsrv/cgi.c'
'Invoking: ARM Ltd Windows GCC C++ Compiler'
"C:/Freescale/CW MCU v10.6/Cross_Tools/arm-none-eabi-gcc-4_7_3/bin/arm-none-eabi-g++" "C:/Freescale/APM_4_1/rtcs/examples/httpsrv/cgi.c" @"Source/cgi.args" -MMD -MP -MF"Source/cgi.d" -o"Source/cgi.o"
'Finished building: C:/Freescale/APM_4_1/rtcs/examples/httpsrv/cgi.c'
' '
'Building file: C:/Freescale/APM_4_1/rtcs/examples/httpsrv/httpdsrv.c'
'Executing target #2 C:/Freescale/APM_4_1/rtcs/examples/httpsrv/httpdsrv.c'
'Invoking: ARM Ltd Windows GCC C++ Compiler'
"C:/Freescale/CW MCU v10.6/Cross_Tools/arm-none-eabi-gcc-4_7_3/bin/arm-none-eabi-g++" "C:/Freescale/APM_4_1/rtcs/examples/httpsrv/httpdsrv.c" @"Source/httpdsrv.args" -MMD -MP -MF"Source/httpdsrv.d" -o"Source/httpdsrv.o"
'Finished building: C:/Freescale/APM_4_1/rtcs/examples/httpsrv/httpdsrv.c'
' '
'Building file: C:/Freescale/APM_4_1/rtcs/examples/httpsrv/tfs_data.c'
'Executing target #3 C:/Freescale/APM_4_1/rtcs/examples/httpsrv/tfs_data.c'
'Invoking: ARM Ltd Windows GCC C++ Compiler'
"C:/Freescale/CW MCU v10.6/Cross_Tools/arm-none-eabi-gcc-4_7_3/bin/arm-none-eabi-g++" "C:/Freescale/APM_4_1/rtcs/examples/httpsrv/tfs_data.c" @"Source/tfs_data.args" -MMD -MP -MF"Source/tfs_data.d" -o"Source/tfs_data.o"
'Finished building: C:/Freescale/APM_4_1/rtcs/examples/httpsrv/tfs_data.c'
' '
'Building target: C:/Freescale/APM_4_1/mqx/examples/cplus/build/cw10gcc/cplus_APM_4_1/Int Flash SramData Debug/cplus.elf'
'Executing target #4 C:/Freescale/APM_4_1/mqx/examples/cplus/build/cw10gcc/cplus_APM_4_1/Int Flash SramData Debug/cplus.elf'
'Invoking: ARM Ltd Windows GCC C++ Linker'
"C:/Freescale/CW MCU v10.6/Cross_Tools/arm-none-eabi-gcc-4_7_3/bin/arm-none-eabi-g++" @"cplus.args" -o"C:/Freescale/APM_4_1/mqx/examples/cplus/build/cw10gcc/cplus_APM_4_1/Int Flash SramData Debug/cplus.elf"
./Source/httpdsrv.o: In function `main_task(unsigned long)':
C:/Freescale/APM_4_1/rtcs/examples/httpsrv/httpdsrv.c:247: undefined reference to `cgi_lnk_tbl'
mingw32-make: *** [C:/Freescale/APM_4_1/mqx/examples/cplus/build/cw10gcc/cplus_APM_4_1/Int Flash SramData Debug/cplus.elf] Error 1

0 Kudos
821 Views
razed11
Contributor V

Hi Lee,

I was able to build, link, run, and browse the pages using IAR. I did add the #ifdef __cplusplus checks to the header I suggested.

Did you try Luis's suggestion? It looks like he invoked some options to adjust the link order. It's been a while since I've dug in to GCC. Try that or move CGI.o earlier in your list of object files. You could also examine the linker output file and verify that that symbol exists but given that you are confident that the file is included then I think Luis had it right all along.

#ifndef __MQXNETWORK_H__

#define __MQXNETWORK_H__

#ifdef __cplusplus

extern "C"

{

#endif

   

    #include <httpsrv.h>

    #include <rtcs.h>

    #include <ipcfg.h>

#ifdef __cplusplus

}

#endif

#endif

0 Kudos
821 Views
LuisCasado
NXP Employee
NXP Employee

Hi Lee,

I have worked with PEG and MQX, mixing C++ and C in some projects and demos with IAR, Keil and CW 10.x (ARM FSL compiler) and with different versions of MQX 3.x and 4.x.

But with CW10.x and GCC compiler found similar issues, the same source code built fine with IAR and Keil, but not with GCC.

So, what I did is to base my project in the cpp MQX example C:\Freescale\Freescale_MQX_4_1\mqx\examples\cplus

Firstly I tried to add the "#define BSPCFG_ENABLE_CPP                    1  in my user_config.h, but it didn't worked for my new created PEG PRO project. I suggest you to review and configure your project settings with the same configuration than "cplus” example or to base your project in that example with the wizard. That worked for me and now I can build PEG code (C++) with MQX code without problems.

I was missing some preprocessor definitions like "_EWL_C99=1” and others…

Best Regards,

Luis

0 Kudos
821 Views
razed11
Contributor V

I used that HTTP server example code as my starting point in my C++ application. I don't believe your issue with cgi_lnk_tbl has anything to do with name-mangling however. It's defined as follows in the demo:

extern const HTTPSRV_CGI_LINK_STRUCT cgi_lnk_tbl[];

I think you just forgot to add cgi.c to your build.

Rather than modify the library headers to use C linkage I suggest you create a header in your code, add the extern "C" around the network-related files, and reference this when needed. I created a "MQXNetwork.h" that looks like this:


#ifndef __MQXNETWORK_H__

#define __MQXNETWORK_H__

extern "C"

{

    #include <httpsrv.h>

    #include <rtcs.h>

    #include <ipcfg.h>

}

#endif

Unrelated to your post I made a request today to add the extern "C" support to the library.

I encourage younger embedded engineers to embrace C++. At least until something better comes along.

822 Views
leepenn
Contributor III


Kenny,

By combining the CGI.c into the RTCS.c the project compiled properly having them separate did not work. Thanks for the help!

0 Kudos
821 Views
LuisCasado
NXP Employee
NXP Employee

Hi Lee,

I had similar issue with PEG and MFS in CW 10.6 and MQX 4.1.1.

Check that you have in the linker settings Miscellaneous -> Linker Flags the line:

--start-group "${MQX_ROOT_DIR}/lib/twrk70f120m.cw10gcc/debug/rtcs/rtcs.a" -Xlinker --end-group

Regards,

Luis

0 Kudos