Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `main' from MATLAB R2017a #2

Open
nearlabnes opened this issue Jun 16, 2019 · 9 comments
Open

undefined reference to `main' from MATLAB R2017a #2

nearlabnes opened this issue Jun 16, 2019 · 9 comments

Comments

@nearlabnes
Copy link

Compiling test.slx this error comes up:

/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function '_start': (.text+0x20): undefined reference to 'main' collect2: error: ld returned 1 exit status gmake: *** [../test_simple] Error 1

It seems that ert_main.c is not correctly linked with the new compiler (MATLAB R2017b).

According to Sriram

I was able to build the model by adding ert_main.c to MODULES inside the model .mk file generated by the template makefile. I am using R2017b and I think this is an issue with the template makefile.
but I was not able to solve the issue, please provide some hints.

https://rtime.felk.cvut.cz/~sojka/blog/on-generating-linux-applications-from-simulink/#comment-1732b017230b5b064a73840bd14ee4fa

@wentasah
Copy link
Member

As mentioned in #1, I'll be able to fix this during August.

@foool
Copy link

foool commented Dec 30, 2019

I met the same "undefined reference to 'main'" problem. Add ert_main.o to dependent libraries to generate the final executable program ($(PRODUCT)) will fix this problem:

$(PRODUCT) : $(OBJS) $(SHARED_LIB) $(LIBS) $(SRC_DEP) $(MODELREF_LINK_LIBS) ert_main.o 
    $(BIN_SETTING) $(LINK_OBJS) ert_main.o $(MODELREF_LINK_LIBS) $(SHARED_LIB) $(LIBFIXPT) $(LIBS)  $(SYSLIBS) 
    @echo "### Created $(BUILD_PRODUCT_TYPE): $@"

This works for me, but don't promise to work in all cases.

@ppisa
Copy link
Contributor

ppisa commented Jan 8, 2020

Hello Qing, I think I have made include of commontargetlib.tlc conditional to be used only with Matlab versions older than 2017a . I have solved problem of need to explicitly include ert_main.o in link for 2017a and later Matlab/Simulink some conditional and hopefully acceptable way

https://github.com/ppisa/ert_linux

There is still problem than undefined reference to rtmGetStopRequested' ert_main.o: In function abort_signal_handler' and rtmGetStopRequested
when there is no S-function in the model. The defines somehow change
out of the control according to use or not use any S-function in the model.

@foool
Copy link

foool commented Jan 9, 2020

Hello Qing, I think I have made include of commontargetlib.tlc conditional to be used only with Matlab versions older than 2017a . I have solved problem of need to explicitly include ert_main.o in link for 2017a and later Matlab/Simulink some conditional and hopefully acceptable way

https://github.com/ppisa/ert_linux

There is still problem than undefined reference to rtmGetStopRequested' ert_main.o: In function abort_signal_handler' and rtmGetStopRequested
when there is no S-function in the model. The defines somehow change
out of the control according to use or not use any S-function in the model.

No S-function in my model, so things are a little different.

You mentioned undefined reference to rtmGetStopRequested error in you build process, and I check my source codes. In rtmodel.h I find its definition, seem to be useless.

    /* Macros generated for backwards compatibility  */
    #ifndef rtmGetStopRequested
    # define rtmGetStopRequested(rtm)      ((void*) 0)
    #endif
    #endif  

@ppisa
Copy link
Contributor

ppisa commented Jan 9, 2020

Please, can you test my fork. Are you using 2017a/b or newer. I have problems with undefined rtmGetStopRequested and rtmSetStopRequested in the case that there is NOT any S-function . If the S-function is used, then result seems OK. Tests run on 2019b.

@foool
Copy link

foool commented Jan 10, 2020

Hi, @ppisa
I forgot to mention I used my own customized my_main.tlc to generate the ert_main.c and it doesn't support external mode. Therefore, the auto-generated codes do not contain rtmSetStopRequested and rtmGetStopRequested functions. rtmSetStopRequested and rtmGetStopRequested are used in external mode to determine to stop model running or not, according control signals from the host.

So my suggestion is to remove the codes which contain the rtmGetStopRequested and rtmSetStopRequested , or define these two functions as follow:

`#define rtmSetStopRequested(x,y) 0

#define rtmGetStopRequested(x) 0`

@ppisa
Copy link
Contributor

ppisa commented Jan 10, 2020

It is easy to overcome, but then some functionality would not work correctly, ability to terminate model etc. All that worked fine with previous Matalb/Simulink versions, so we do not want to lose these capabilities at Department of Control Engineering FEE CTU (https://dce.fel.cvut.cz/en) where this target has been designed and is used. By the way we have nice Xilix Zynq setup which allows to run the DC, PMSM and other stuff with this target on Xilinx Zynq based systems as well as on Raspberry Pi

We would be happy if you can use some of our projects. If you have some fixes, enhancements or alternative uses for the project we would be pleased if you can send us link to your repository, patches, sources or even references.

@foool
Copy link

foool commented Jan 11, 2020

Great job! I am working on Linux & high-performance real-time simulation in the last year, and your lintarget and ert_linux projects help me a lot for starting. For different MATLAB versions, I frequently met compatibility problems to generate source codes from models when applying some non-official System Target Files(STF), and it may be burdensome to create all-round system target files applicable to all versions. Now I am using toolchain to automatically generate the Makefile, which avoid some dependency problems. But my STF is just a start-up, and I would be happy to open-source it if it have better compatibility and support more features(concurrent execution and etc.)

@ppisa
Copy link
Contributor

ppisa commented Feb 15, 2020

Martin Gurtner from our department AA4CC (Advanced Algorithms for Control and Communications http://aa4cc.dce.fel.cvut.cz/ ) has integrated changes and prepared unified example which can be build for native Linux, ARM and ARM64/AArch64 by one double-click on a corresponding button and run on target by another double-click. See the repo https://github.com/aa4cc/ert_linux . All works well on 2017a Matlab/Simulink version. The port to further versions would require more work. Contributions welcomed. Consultations with Humusoft company are planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants