math function failing
-
From the looks of it, you are not linking to the math library.
-
Hi
-Can anybody throw some light why the same is happening despite math.h is included in the same file?Well if you are not on the same platform, it can be that Cmake cant find the math lib to link against.
- . Is there anyway to know what to do if no response is given in the forum?
There are other coding places to ask also. Like StackOverflow.
But make sure you write good questions as it's impossible to help if clear information is not
provided.But normally we do answer most questions here :)
-
@mrjj it is linking time problem undestood but do not know how to fix it in Qt. Single file with #include<math.h> is working alright. Pl. advise if any other sources to explore for the solution.
-
@goswami
Please show the linker line being executed. So far as I am aware, linking with math library is achieved via-lm
option.wrote on 16 Aug 2022, 13:08 last edited by@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. -
@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.wrote on 16 Aug 2022, 13:11 last edited by@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.
-
@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)
-
wrote on 18 Aug 2022, 12:58 last edited by
@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.
-
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.
17/18