Author Topic: Why windows don't show this error but i get this?  (Read 353 times)

Offline Alif

  • Single posting newcomer
  • *
  • Posts: 8
Why windows don't show this error but i get this?
« 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12739
    • Travis build status
Re: Why windows don't show this error but i get this?
« Reply #1 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.
(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!]

Offline Alif

  • Single posting newcomer
  • *
  • Posts: 8
Re: Why windows don't show this error but i get this?
« Reply #2 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: [Select]
#include <math.h>
#include <stdio.h>
int main()
{
    int n=9;
    n= sqrt(n);
    printf("%d",n);
    return 0;
}

error is
Code: [Select]
-------------- 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(?)

Offline Miguel Gimenez

  • Regular
  • ***
  • Posts: 489

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12739
    • Travis build status
Re: Why windows don't show this error but i get this?
« Reply #4 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:
(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!]

Offline Alif

  • Single posting newcomer
  • *
  • Posts: 8
Re: Why windows don't show this error but i get this?
« Reply #5 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.

Offline Alif

  • Single posting newcomer
  • *
  • Posts: 8
Re: Why windows don't show this error but i get this?
« Reply #6 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.