News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Why windows don't show this error but i get this?

Started by Alif, July 28, 2020, 04:44:55 PM

Previous topic - Next topic

Alif

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.

oBFusCATed

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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Alif

Quote from: 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.
os Manjaro Linux; Build ID: rolling
Gnome version:3.36.4
codeblocks version: 20.03-1
compiler: GNU GCC compiler

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


error is
-------------- 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(?)


oBFusCATed

This is odd, compiling and linking with a single command works without -lm, but a two step compilation requires -lm. :shrug:
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Alif

Quote from: 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:

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.

Alif

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.