math function failing
-
Hi,
I would say that you are missing
std::
before your floor calls. -
@SGaist The code is auto generated by a tool called Dymola. They insist for Visual Studio but I wanted to try on Qt Creator. It is appearing linking failure. The error message in Qt Creator is as below
:-1: error: CMakeFiles/app.dir/Bool_Multi/sources/all.c.o: in functionModelicaInternal_temporaryFileName': :-1: error: CMakeFiles/app.dir/Bool_Multi/sources/all.c.o: in function
Mat_VarDelete':
:-1: error: CMakeFiles/app.dir/Bool_Multi/sources/all.c.o: in functiondivideDymola': /home/skgoswami/Desktop/DymolaTest/FMI_Stdalone_Bool_multi_proj/Bool_Multi/sources/dsutil.h:789: error: undefined reference to
floor'
:-1: error: /home/skgoswami/Desktop/DymolaTest/FMI_Stdalone_Bool_multi_proj/Bool_Multi/sources/dsutil.h:789: undefined reference toceil' :-1: error: CMakeFiles/app.dir/Bool_Multi/sources/all.c.o: in function
modulusDymola':
/home/skgoswami/Desktop/DymolaTest/FMI_Stdalone_Bool_multi_proj/Bool_Multi/sources/dsutil.h:792: error: undefined reference to `floor' -
Visual Studio designate both the IDE and the set of tools, Qt Creator is just an IDE.
But it looks like you are working on Linux so can you explain your environment ?
-
I exactly could not understand what you meant by environment. Yes mine is ubuntu 20.04.4, Qt creator 7.0.2, cmake 3.21.1. gcc by default 64bit. The builder is being used 'ninja' by default. I found users faced problem with math.h linking. However I am not getting any problem if I make a simple program as reported by those users. However error is same undefined reference. Incidentally the application is C and hence std:: is not acceptable. I am better providing the content of CMakeLists.txt file for your ready reference below
cmake_minimum_required (VERSION 3.7)
set (MODEL_NAME Bool_Multi)
project (Bool_Multi LANGUAGES C)
add_executable(app
include/fmi2Functions.h
include/fmi2FunctionTypes.h
include/fmi2TypesPlatform.h
src/bool_multi.c
Bool_Multi/sources/all.c
)
target_include_directories(app PUBLIC
include
Bool_Multi/sources
) -
From the looks of it, you are not linking to the math library.
-
@JonB I am using Qt IDE with cmake for building. Following code is working alright
#include <stdio.h>
#include <math.h>
int main()
{
printf("Hello World!=%f\n",pow(2.0,2.0));
return 0;
}
And CMakeLists.txt content is as below
cmake_minimum_required(VERSION 3.5)
project(untitled1 LANGUAGES C)
add_executable(untitled1 main.c)
I do not know how to check linker option in Qt IDE. This is reasonably big project and impossible to go for command line building. -
@goswami said in math function failing:
I do not know how to check linker option in Qt IDE
Did you try looking in the Build Output pane? I don't know, that would be my guess. And I don't know about cmake so I'll leave you with others to respond.
-
target_link_libraries(untitled1 m)
-
@SGaist said in math function failing:
target_link_libraries(untitled1 m)
Many thanks all math.h related errors have gone and the application is giving output. Can you throw some light why the same is not failing when only one file with math.h include is there? Another as it is appearing all #include of libraries are not creating problem. Is it system dependant viz. may compile in one environment but fail in somewhere?
I am really grateful over the efforts you have put to help me out of this crisis which became a serious bottleneck for progress to next stage. -
It depends on the library and what is used of them.
Some are header only, some are template based so it really depends on what you use from these and how they are implemented. It's usually not tied to a specific OS.