Code::Blocks Forums

User forums => Help => Topic started by: Alif on July 28, 2020, 04:44:55 pm

Title: Why windows don't show this error but i get this?
Post by: Alif on July 28, 2020, 04:44:55 pm
I'm sorry if I make any mistake in writting. I've gone to to the rules as you asked.
By the way,
 I came to know after searching the net for a while; windows don't show an error /*undefined refferences*/ while using sqrt() or pow() functions. But in linux it shows.
so i just want to know what is the speciality of windows then?
Then I'll request you a thing that Is it possible to link "m" by default in the compiler settings? so that new linux user don't get scared or frustated with linux.   They will think linux always causes problems. Please say  something.
Title: Re: Why windows don't show this error but i get this?
Post by: oBFusCATed on July 28, 2020, 09:47:21 pm
Linking libm is not required to do manually if you're using the correct linker (gcc or g++).

So you'll have to post more details like full build log, screenshot of the toolchain executables and os/compiler/codeblocks version numbers.
Title: Re: Why windows don't show this error but i get this?
Post by: Alif on July 29, 2020, 02:48:29 pm
Linking libm is not required to do manually if you're using the correct linker (gcc or g++).

So you'll have to post more details like full build log, screenshot of the toolchain executables and os/compiler/codeblocks version numbers.
os Manjaro Linux; Build ID: rolling
 Gnome version:3.36.4
codeblocks version: 20.03-1
compiler: GNU GCC compiler

for this code:
Code
#include <math.h>
#include <stdio.h>
int main()
{
    int n=9;
    n= sqrt(n);
    printf("%d",n);
    return 0;
}

error is
Code
-------------- Build file: "no target" in "no project" (compiler: unknown)---------------

gcc   -c /home/ali/Documents/codeblocks_codes/error.c -o /home/ali/Documents/codeblocks_codes/error.o
gcc  -o /home/ali/Documents/codeblocks_codes/error /home/ali/Documents/codeblocks_codes/error.o   
/usr/bin/ld: /home/ali/Documents/codeblocks_codes/error.o: in function `main':
error.c:(.text+0x23): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 
some people are saying that windows dosen't show this error(?)
Title: Re: Why windows don't show this error but i get this?
Post by: Miguel Gimenez on July 29, 2020, 04:01:00 pm
MinGW does not use a math library, see for example:

https://stackoverflow.com/questions/48134247/why-i-dont-need-the-flag-lm-in-mingw-but-in-linux-i-need-that-explicitly (https://stackoverflow.com/questions/48134247/why-i-dont-need-the-flag-lm-in-mingw-but-in-linux-i-need-that-explicitly)
Title: Re: Why windows don't show this error but i get this?
Post by: oBFusCATed on July 29, 2020, 07:08:04 pm
This is odd, compiling and linking with a single command works without -lm, but a two step compilation requires -lm. :shrug:
Title: Re: Why windows don't show this error but i get this?
Post by: Alif on July 30, 2020, 04:32:47 am
This is odd, compiling and linking with a single command works without -lm, but a two step compilation requires -lm. :shrug:

I request to fix this. I have linked 'm' in my compiler settings> linker settings. But I had to waste an amount of time to figure that out.

And another thing; I am using manjaro gnome and inside it, codeblocks. When I tried to run the first code in this new operating system; it was compiled and no error but the program was not running.  :-\ Then I wasted some time to figure it out that -- "xterm" was set as the default terminal emulator and wasn't installed in the system. Then I changed my default terminal emulator and also installed "xterm" for other users. Codeblocks can't select the available terminal emulator?  :'( or install xterm as a dependency?

This two things. I wanted to inform you to make codeblocks better.
Title: Re: Why windows don't show this error but i get this?
Post by: Alif on August 03, 2020, 11:51:28 am
the problem is now solved. I don't know exactly how it happened. but i've created a new user and restored a older system snapshot.