C - Undefined reference - is there an alternative to compiling with -lm? - c

I have a problem much like the one here where the error is "Undefined reference to sqrt". I understand how using the -lm flag when compiling fixes the problem by linking it to the math library, however, are there any other possible ways to fix the problem without using any special compiler flags?
I've been happily using "-lm" while compiling my project so far, but my instructor uses try which won't accept a submission unless it compiles.... they do not use -lm.
Is there a way to solve this that doesn't require me to write my own square root function?

Other than making your own sqrt method no, though some compilers have the sqrt function already in them from what I've used so you may not need the extra flag potentially. I would email your instructor and talk to him about this.

Related

Examples of 'falign-loops' optimisation occuring?

One pass run by the compiler when optimising in gcc is falign-loops.
Although a vague description is provided here: https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/data-options/falign-loops-qalign-loops.html
It is listed as one of the optimisations occurring with the -O2 flag here:
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
I have been unable to actually see it work in action with any piece of code I have tried using compiler explorer. Does anyone know how the flag functions and perhaps have some explicit examples?
Thanks

How do I configure GCC to include header files automatically? [duplicate]

I have a problem much like the one here where the error is "Undefined reference to sqrt". I understand how using the -lm flag when compiling fixes the problem by linking it to the math library, however, are there any other possible ways to fix the problem without using any special compiler flags?
I've been happily using "-lm" while compiling my project so far, but my instructor uses try which won't accept a submission unless it compiles.... they do not use -lm.
Is there a way to solve this that doesn't require me to write my own square root function?
Other than making your own sqrt method no, though some compilers have the sqrt function already in them from what I've used so you may not need the extra flag potentially. I would email your instructor and talk to him about this.

Having trouble getting date and time in C. I've searched for answers and tried many but none work,

My assignment is to use unix system calls or library utilities in C to get an answer, and I've been searching for a while, All the answers available seem to lead to something with localtime() or time strftime() and I keep getting these warnings that say the functions are unsafe. I've been trying examples and copy pasting code but nothing seems to compile usually with the unsafe error. Help. Extra details, I can't use any libraries out of the very standard ones, things like chrono have gotten my friend rejected work before.
If you're required to turn in the work using the 'traditional' library functions like strftime(), then you'll need to turn off the warnings about these functions being unsafe.
There's usually some way to do this, but it will depend what specific compiler you're using, and you didn't say.
There's nothing particularly 'wrong' with solutions using these functions, it's just that times have moved on since they were originally developed, and many people try to avoid the potential security risks associated with their use.
Have you tried using whats available in the time header? As far as I know, the time.h header should be available to any C compiler.
Some more information to read up on:
http://en.wikipedia.org/wiki/C_date_and_time_functions

CPLEX, C coding

I am coding in C an optimization problem on linux. I am using CPLEX to solve this optimization problem.
I wrote my code and everything, but when i'm trying to compile in the terminal, I am getting such errors:
etc.... I am trying to change in my code the CPX to CPXX but still
I have a 64-bit machine
model.c is the name of my C file.model.c:(.text+0x115c): undefined reference to "CPXnewrows"
model.c:(.text+0x121b): undefined reference to "CPXchgcoeflist"
model.c:(.text+0xd62): undefined reference to "CPXnewcols"
Please any help would be more than grateful!!!
Those are linker errors. You need to link the CPLEX library with model.c.
This link might have some applicable information on how to do this on Linux.

Compiling errors in a program using threads

On compiling I am getting an error "undefined reference to pthread_create()" and similarly for "undefined reference to pthread_join()". What are the possible reasons? I am unable to identify them.
Are you sure you remembered the -lpthread flag in compilation? Usually that's the source of this error.
You should add -pthread, which adds the required flags for the preprocessor as well as the linker. The flag suggested by others, -lpthread, only links the library, which may lead to the system libraries not having proper threading support.

Resources