GSL and gsl_linalg_cholesky_invert - c

I'm using the gsl library in a c code. Everything goes fine but when i use the command gsl_linalg_cholesky_invert the terminal shows the following message:
Undefined symbols for architecture x86_64:"_gsl_linalg_cholesky_invert", referenced from:
_main in cc4eefuQ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
A code example is the following.
#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_linalg.h>
#include <math.h>
void main()
{
gsl_matrix * A = gsl_matrix_calloc (2,2);
gsl_matrix_set(A,0,0,1);
gsl_matrix_set(A,0,1,0.5);
gsl_matrix_set(A,1,0,0.5);
gsl_matrix_set(A,1,1,1);
gsl_linalg_cholesky_decomp(A);
gsl_linalg_cholesky_invert(A);
}
If i comment out the line gsl_linalg_cholesky_invert(A);, everything goes fine.
I compile the code with the following command:
gcc-mp-4.7 wrapnorm.c -o wrapnorm -lgsl -l gslcblas -lm
with a macbook pro with mountain lion and gsl version 1.9.
Thanks

Related

Can't use "get_int" in libcs50 for C

So I'm currently new to C right now, and I just downloaded the cs50 library. I tried to make an input by using get_int(), but it's not working. Here's my code:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int i = get_int("Input: ");
printf("Output: %i\n", i);
}
This is the error that I got
cc calculator.c -o calculator
Undefined symbols for architecture x86_64:
"_get_int", referenced from:
_main in calculator-225c65.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [calculator] Error 1

how to solve this problem compiler error that linker command failed in VSCODE

I wrote some C code on VSCODE like that.
The code is divided into three files: the header, the function, and main in same project folder.
But when I started compile, files are can't compile and error. like terminal text.
Maybe I think this error is linking error..
How to solve this problem..?
[source code]
mysqrt.c
#include "mysqrt.h"
#include <stdio.h>
#include <math.h>
double mysqrt(double a, double b){
double result = sqrt(pow(a,2)+pow(b,2));
return result;
}
mysqrt.h
#include <stdio.h>
double mysqrt(double a, double b);
mysqrtTest.c
#include <stdio.h>
#include <math.h>
#include "mysqrt.h"
void main(void){
double sum = mysqrt(3,4);
printf("%.2f\n",sum);
}
[terminal text]
/Users/kim_donggyun/Desktop/My File/MyFile/VSCodeWorkFolder/2019_2_finalExam/mysqrtTest.c:5:1: warning:
return type of 'main' is not 'int' [-Wmain-return-type]
void main(void){
^
/Users/kim_donggyun/Desktop/My File/MyFile/VSCodeWorkFolder/2019_2_finalExam/mysqrtTest.c:5:1: note: change
return type to 'int'
void main(void){
^~~~
int
1 warning generated.
Undefined symbols for architecture x86_64:
"_mysqrt", referenced from:
_main in mysqrtTest-45c3c1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[OS]: macOS Mojave 10.14.6
to resolve your linking issue you need to compile all your c file, as dependencies are not automatically resolved ( header files could be name separately from code file so .h files and .c files are independant ).
# assuming that gcc is your compiler
gcc -Wall -Wextra -Werror -pedantic -o mysqrtTest mysqrtTest.c mysqrt.c -lm
Although I would recommend you to learn about separate compilation, and using a build system, like make
Example of Makefile
mysqrtTest: mysqrtTest.o mysqrt.o
${CC} -o $# $^ -lm
then use make to build your binary

Link tidylib library to C application

I am trying to use the tidylib library within my C application. When compiling, I get the following errors:
$ make
rm -f sbo-export
cc sbo-export.c safarilib.c -L/usr/local/lib -lcurl -L/usr/local/Cellar/libtidy/lib -I/usr/local/Cellar/libtidy/include -o sbo-export
Undefined symbols for architecture x86_64:
"_tidyCreate", referenced from:
_safari_init_session in safarilib-c7ab6a.o
"_tidyParseString", referenced from:
_safari_init_session in safarilib-c7ab6a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [default] Error 1
safarilib.c:
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <tidy/tidy.h>
#include <tidy/buffio.h>
#include <curl/curl.h>
#include "safarilib.h"
void usage( char *username, char *password )
{
TidyDoc tdoc = tidyCreate();
char *input = "<html><body><h1>Hello World!</h1></body></html>";
tidyParseString( tdoc, input );
}
Any suggestions?
Further Infos:
For installing libtidy, I did the following:
Downloaded libtidy from http://tidy.sourceforge.net and then
followed the instructions form the file tidy/build/readme.txt
My library is installed here:
/usr/local/Cellar/libtidy
/usr/local/Cellar/libtidy/bin
/usr/local/Cellar/libtidy/bin/tab2space
/usr/local/Cellar/libtidy/bin/tidy
/usr/local/Cellar/libtidy/include
/usr/local/Cellar/libtidy/include/buffio.h
/usr/local/Cellar/libtidy/include/platform.h
/usr/local/Cellar/libtidy/include/tidy.h
/usr/local/Cellar/libtidy/include/tidyenum.h
/usr/local/Cellar/libtidy/lib
/usr/local/Cellar/libtidy/lib/libtidy-0.99.0.dylib
/usr/local/Cellar/libtidy/lib/libtidy.a
/usr/local/Cellar/libtidy/lib/libtidy.dylib
/usr/local/Cellar/libtidy/lib/libtidy.la
From compiler option it's look you have not specified tidylib.
cc sbo-export.c safarilib.c -L/usr/local/lib -lcurl -L/usr/local/Cellar/libtidy/lib -I/usr/local/Cellar/libtidy/include -o sbo-export
Here you need to add -ltidy and probably path by -L .
Some additional info about linking.

undefined reference to `roundf' - C language

I'm new to C and I keep running into the same error. I am typing the code in nano text editor and compiling it in the linux terminal. My operating system is Ubuntu 14.04. Here's an example of code that won't compile,
#include <math.h>
#include <stdio.h>
int main()
{
float x = 23.33f;
x = roundf(x);
printf("%f\n", x);
return (0);
}
The error I am receiving is,
cc example.c -o example
/tmp/ccWV0Or8.o: In function `main':
example.c:(.text+0x1d): undefined reference to `roundf'
collect2: error: ld returned 1 exit status
make: *** [example] Error 1
Any help is much appreciated, thanks!
Link with the math library:
cc example.c -o example -lm
The math library functions are not part of standard C library which is linked by default. So you need link it yourself.
There's an interesting thread about why it's not part of libc:
Why do you have to link the math library in C?

Using nan() on solaris-sparc

#include <math.h>
int main() {
nan("");
}
The above code works on Linux with gcc fn.c -lm. It doesn't on solaris-sparc. How do I fix this?
The error message is:
Undefined symbol nan, first referenced in file /var/tmp//ccsdneUZ.o ld: fatal: Symbol referencing errors. No output written to test collect2: ld returned 1 exit status.

Resources