clang: error: linker command failed with exit code 1 (use -v to see invocation)

Hi,
I am new to igraph C. I am trying to install it in Ubuntu 20.04.2 LTS. While I compiling C Igraph program using this command line -

clang++ igraph.cpp -I/home/iit/include/igraph -L/home/iit/lib -ligraph -o igraph

or

gcc igraph_test.c -I/home/iit/include/igraph -L/home/iit/lib -ligraph -o igraph_test

it’s showing this error-

**warning:** 'igraph_i_set_attribute_table' is deprecated [-Wdeprecated-declarations]
        igraph_i_set_attribute_table(&igraph_cattribute_table);
        ^
/home/iit/include/igraph/igraph_attributes.h:334:15: note: 'igraph_i_set_attribute_table' has been explicitly marked deprecated here
IGRAPH_EXPORT IGRAPH_DEPRECATED igraph_attribute_table_t * igraph_i_set_attribute_table(const igraph_attribute_table_t * table);
              ^
/home/iit/include/igraph/igraph_export.h:25:45: note: expanded from macro 'IGRAPH_DEPRECATED'
#  define IGRAPH_DEPRECATED __attribute__ ((__deprecated__))
                                            ^
1 warning generated.
/usr/bin/ld: /usr/local/lib/libigraph.a(sparsemat.c.o): in function `igraph_sparsemat_symbolic_destroy':
sparsemat.c:(.text+0x1c): undefined reference to `cs_di_sfree'
/usr/bin/ld: /usr/local/lib/libigraph.a(sparsemat.c.o): in function `igraph_sparsemat_numeric_destroy':
sparsemat.c:(.text+0x3c): undefined reference to `cs_di_nfree'
/usr/bin/ld: /usr/local/lib/libigraph.a(sparsemat.c.o): in function `igraph_i_sparsemat_arpack_multiply':
sparsemat.c:(.text+0x140): undefined reference to `cs_di_gaxpy'
/usr/bin/ld: /usr/local/lib/libigraph.a(sparsemat.c.o): in function `igraph_sparsemat_init':
sparsemat.c:(.text+0x1a2): undefined reference to `cs_di_spalloc'
/usr/bin/ld: /usr/local/lib/libigraph.a(sparsemat.c.o): in function `igraph_sparsemat_copy':
sparsemat.c:(.text+0x274): undefined reference to `cs_di_spalloc'
........................

/usr/bin/ld: /usr/local/lib/libigraph.a(arpack.c.o): in function `igraph_arpack_rssort':
arpack.c:(.text+0x712): undefined reference to `dsortr_'
/usr/bin/ld: /usr/local/lib/libigraph.a(arpack.c.o): in function `igraph_arpack_rnsort':
arpack.c:(.text+0xb85): undefined reference to `dsortc_'
/usr/bin/ld: /usr/local/lib/libigraph.a(arpack.c.o): in function `igraph_arpack_rssolve':
arpack.c:(.text+0x13d9): undefined reference to `dsaupd_'
/usr/bin/ld: arpack.c:(.text+0x1473): undefined reference to `dseupd_'
/usr/bin/ld: /usr/local/lib/libigraph.a(arpack.c.o): in function `igraph_arpack_rnsolve':
arpack.c:(.text+0x24ed): undefined reference to `dnaupd_'
/usr/bin/ld: arpack.c:(.text+0x25b3): undefined reference to `dneupd_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If you built igraph as a static library (libigraph.a), then you must manually link to all of its external dependencies when building a program that uses it. Which are these external dependencies depends on how igraph was compiled. The summary output from CMake should give a good hint.

If igraph was installed in a standard location, you can get the linker flags using pkg-config --libs --cflags igraph, otherwise you can look in the igraph.pc file.

The simplest way is probably to build a shared library, which knows its dependencies. You won’t need to explicitly list them yourself.

I reinstall igraph and run this igraph_test.c basic code.
But again showing this type of error -

/usr/bin/ld: /home/iit/lib/libigraph.a(random.c.o): in function `igraph_qnorm5.part.0':
random.c:(.text+0x370): undefined reference to `expm1'
/usr/bin/ld: random.c:(.text+0x4a1): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x511): undefined reference to `expm1'
/usr/bin/ld: random.c:(.text+0x580): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x799): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x7e0): undefined reference to `sqrt'
/usr/bin/ld: /home/iit/lib/libigraph.a(random.c.o): in function `igraph_rng_get_binom':
random.c:(.text+0x124b): undefined reference to `fmin'
/usr/bin/ld: random.c:(.text+0x161e): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x172e): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x18f3): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x19d2): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x1a01): undefined reference to `log'
/usr/bin/ld: /home/iit/lib/libigraph.a(random.c.o):random.c:(.text+0x1a2f): more undefined references to `log' follow
/usr/bin/ld: /home/iit/lib/libigraph.a(random.c.o): in function `igraph_rng_get_binom':
random.c:(.text+0x1c68): undefined reference to `pow'
/usr/bin/ld: random.c:(.text+0x1e05): undefined reference to `sqrt'
/usr/bin/ld: /home/iit/lib/libigraph.a(random.c.o): in function `igraph_random_sample':
random.c:(.text+0x210f): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x211a): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x226d): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x2278): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x2349): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x2354): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x23a8): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x23b3): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x25ce): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x25d9): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x28dd): undefined reference to `round'
/usr/bin/ld: /home/iit/lib/libigraph.a(random.c.o): in function `igraph_rng_get_geom':
random.c:(.text+0x3b86): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x3ba5): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x3d05): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x3e7f): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x3ee7): undefined reference to `pow'
/usr/bin/ld: random.c:(.text+0x3f56): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x3fe6): undefined reference to `sqrt'
/usr/bin/ld: random.c:(.text+0x4037): undefined reference to `sqrt'
/usr/bin/ld: /home/iit/lib/libigraph.a(random.c.o): in function `igraph_rgamma':
random.c:(.text+0x429d): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x42c4): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4349): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4353): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x46a8): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4859): undefined reference to `expm1'
/usr/bin/ld: random.c:(.text+0x48a7): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x495b): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4c10): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4cb8): undefined reference to `sqrt'
/usr/bin/ld: /home/iit/lib/libigraph.a(random.c.o): in function `igraph_dnorm':
random.c:(.text+0x4e94): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4ef1): undefined reference to `exp'
/usr/bin/ld: /home/iit/lib/libigraph.a(erdos_renyi.c.o): in function `igraph_erdos_renyi_game_gnp':
erdos_renyi.c:(.text+0x428): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x4f4): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x6f0): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x7e0): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x8d5): undefined reference to `sqrt'
/usr/bin/ld: erdos_renyi.c:(.text+0x8f6): undefined reference to `sqrt'
/usr/bin/ld: /home/iit/lib/libigraph.a(erdos_renyi.c.o): in function `igraph_erdos_renyi_game_gnm':
erdos_renyi.c:(.text+0xba3): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0xd44): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0xecf): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0xfff): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x10e7): undefined reference to `sqrt'
/usr/bin/ld: erdos_renyi.c:(.text+0x1111): undefined reference to `sqrt'
/usr/bin/ld: /home/iit/lib/libigraph.a(vector.c.o): in function `igraph_vector_floor':
vector.c:(.text+0x1bbc8): undefined reference to `floor'
/usr/bin/ld: /home/iit/lib/libigraph.a(vector.c.o): in function `igraph_vector_round':
vector.c:(.text+0x1bc98): undefined reference to `round'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_polar':
complex.c:(.text+0x6d): undefined reference to `sincos'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_div':
complex.c:(.text+0x2e8): undefined reference to `hypot'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_inv':
complex.c:(.text+0x6a4): undefined reference to `hypot'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_logabs':
complex.c:(.text+0x741): undefined reference to `log'
/usr/bin/ld: complex.c:(.text+0x759): undefined reference to `log1p'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_sqrt':
complex.c:(.text+0x928): undefined reference to `sqrt'
/usr/bin/ld: complex.c:(.text+0x96a): undefined reference to `sqrt'
/usr/bin/ld: complex.c:(.text+0x9ac): undefined reference to `sqrt'
/usr/bin/ld: complex.c:(.text+0x9fc): undefined reference to `sqrt'
/usr/bin/ld: complex.c:(.text+0xa44): undefined reference to `sqrt'
...................
/usr/bin/ld: complex.c:(.text+0x18d4): undefined reference to `sin'
/usr/bin/ld: complex.c:(.text+0x18f9): undefined reference to `sinh'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_csc':
complex.c:(.text+0x1944): undefined reference to `sin'
/usr/bin/ld: complex.c:(.text+0x1977): undefined reference to `hypot'
/usr/bin/ld: complex.c:(.text+0x19de): undefined reference to `cosh'
/usr/bin/ld: complex.c:(.text+0x19fc): undefined reference to `cos'
/usr/bin/ld: complex.c:(.text+0x1a10): undefined reference to `sinh'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_cot':
complex.c:(.text+0x1a59): undefined reference to `hypot'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_mod':
complex.c:(.text+0xe5): undefined reference to `hypot'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_arg':
complex.c:(.text+0x131): undefined reference to `atan2'
/usr/bin/ld: /home/iit/lib/libigraph.a(complex.c.o): in function `igraph_complex_abs':
complex.c:(.text+0x705): undefined reference to `hypot'
/usr/bin/ld: /home/iit/lib/libigraph.a(utils.c.o): in function `igraph_log2':
utils.c:(.text+0x29): undefined reference to `log'
/usr/bin/ld: /home/iit/lib/libigraph.a(utils.c.o): in function `igraph_log1p':
utils.c:(.text+0x389): undefined reference to `log'
collect2: error: ld returned 1 exit status

You do not show the command you used to compile this program. Since you are still compiling igraph into a static library, did you add the linking flags I suggested?

iit@iit-ROG-Strix-G532LWS-G532LWS:~$ gcc igraph_test.c -I/usr/local/include/igraph -L/usr/local/lib -ligraph -o igraph_test
/usr/bin/ld: /usr/local/lib/libigraph.a(random.c.o): in function `igraph_qnorm5.part.0':
random.c:(.text+0x370): undefined reference to `expm1'
/usr/bin/ld: random.c:(.text+0x4a1): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x511): undefined reference to `expm1'
/usr/bin/ld: random.c:(.text+0x580): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x799): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x7e0): undefined reference to `sqrt'
/usr/bin/ld: /usr/local/lib/libigraph.a(random.c.o): in function `igraph_rng_get_binom':
random.c:(.text+0x124b): undefined reference to `fmin'
/usr/bin/ld: random.c:(.text+0x161e): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x172e): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x18f3): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x19d2): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x1a01): undefined reference to `log'
/usr/bin/ld: /usr/local/lib/libigraph.a(random.c.o):random.c:(.text+0x1a2f): more undefined references to `log' follow
/usr/bin/ld: /usr/local/lib/libigraph.a(random.c.o): in function `igraph_rng_get_binom':
random.c:(.text+0x1c68): undefined reference to `pow'
/usr/bin/ld: random.c:(.text+0x1e05): undefined reference to `sqrt'
/usr/bin/ld: /usr/local/lib/libigraph.a(random.c.o): in function `igraph_random_sample':
random.c:(.text+0x210f): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x211a): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x226d): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x2278): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x2349): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x2354): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x23a8): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x23b3): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x25ce): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x25d9): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x28dd): undefined reference to `round'
/usr/bin/ld: /usr/local/lib/libigraph.a(random.c.o): in function `igraph_rng_get_geom':
random.c:(.text+0x3b86): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x3ba5): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x3d05): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x3e7f): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x3ee7): undefined reference to `pow'
/usr/bin/ld: random.c:(.text+0x3f56): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x3fe6): undefined reference to `sqrt'
/usr/bin/ld: random.c:(.text+0x4037): undefined reference to `sqrt'
/usr/bin/ld: /usr/local/lib/libigraph.a(random.c.o): in function `igraph_rgamma':
random.c:(.text+0x429d): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x42c4): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4349): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4353): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x46a8): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4859): undefined reference to `expm1'
/usr/bin/ld: random.c:(.text+0x48a7): undefined reference to `exp'
/usr/bin/ld: random.c:(.text+0x495b): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4c10): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4cb8): undefined reference to `sqrt'
/usr/bin/ld: /usr/local/lib/libigraph.a(random.c.o): in function `igraph_dnorm':
random.c:(.text+0x4e94): undefined reference to `log'
/usr/bin/ld: random.c:(.text+0x4ef1): undefined reference to `exp'
/usr/bin/ld: /usr/local/lib/libigraph.a(erdos_renyi.c.o): in function `igraph_erdos_renyi_game_gnp':
erdos_renyi.c:(.text+0x428): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x4f4): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x6f0): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x7e0): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x8d5): undefined reference to `sqrt'
/usr/bin/ld: erdos_renyi.c:(.text+0x8f6): undefined reference to `sqrt'
/usr/bin/ld: /usr/local/lib/libigraph.a(erdos_renyi.c.o): in function `igraph_erdos_renyi_game_gnm':
erdos_renyi.c:(.text+0xba3): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0xd44): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0xecf): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0xfff): undefined reference to `floor'
/usr/bin/ld: erdos_renyi.c:(.text+0x10e7): undefined reference to `sqrt'
/usr/bin/ld: erdos_renyi.c:(.text+0x1111): undefined reference to `sqrt'
/usr/bin/ld: /usr/local/lib/libigraph.a(vector.c.o): in function `igraph_vector_floor':
vector.c:(.text+0x1bbc8): undefined reference to `floor'
/usr/bin/ld: /usr/local/lib/libigraph.a(vector.c.o): in function `igraph_vector_round':
vector.c:(.text+0x1bc98): undefined reference to `round'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_polar':
complex.c:(.text+0x6d): undefined reference to `sincos'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_div':
complex.c:(.text+0x2e8): undefined reference to `hypot'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_inv':
complex.c:(.text+0x6a4): undefined reference to `hypot'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_logabs':
complex.c:(.text+0x741): undefined reference to `log'
/usr/bin/ld: complex.c:(.text+0x759): undefined reference to `log1p'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_sqrt':
complex.c:(.text+0x928): undefined reference to `sqrt'
/usr/bin/ld: complex.c:(.text+0x96a): undefined reference to `sqrt'
/usr/bin/ld: complex.c:(.text+0x9ac): undefined reference to `sqrt'
/usr/bin/ld: complex.c:(.text+0x9fc): undefined reference to `sqrt'
/usr/bin/ld: complex.c:(.text+0xa44): undefined reference to `sqrt'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o):complex.c:(.text+0xaec): more undefined references to `sqrt' follow
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_exp':
complex.c:(.text+0xb3f): undefined reference to `exp'
/usr/bin/ld: complex.c:(.text+0xb5d): undefined reference to `sincos'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_pow':
complex.c:(.text+0xc74): undefined reference to `log'
/usr/bin/ld: complex.c:(.text+0xc8c): undefined reference to `log1p'
/usr/bin/ld: complex.c:(.text+0xcb7): undefined reference to `atan2'
/usr/bin/ld: complex.c:(.text+0xced): undefined reference to `exp'
/usr/bin/ld: complex.c:(.text+0xd25): undefined reference to `sincos'
/usr/bin/ld: complex.c:(.text+0xdb4): undefined reference to `hypot'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_pow_real':
complex.c:(.text+0xeb1): undefined reference to `log'
/usr/bin/ld: complex.c:(.text+0xeca): undefined reference to `log1p'
/usr/bin/ld: complex.c:(.text+0xee9): undefined reference to `atan2'
/usr/bin/ld: complex.c:(.text+0xf11): undefined reference to `exp'
/usr/bin/ld: complex.c:(.text+0xf35): undefined reference to `sincos'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_log':
complex.c:(.text+0xfe9): undefined reference to `log'
/usr/bin/ld: complex.c:(.text+0x1001): undefined reference to `log1p'
/usr/bin/ld: complex.c:(.text+0x1086): undefined reference to `atan2'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_log10':
complex.c:(.text+0x10f9): undefined reference to `log'
/usr/bin/ld: complex.c:(.text+0x1111): undefined reference to `log1p'
/usr/bin/ld: complex.c:(.text+0x11a6): undefined reference to `atan2'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_log_b':
complex.c:(.text+0x123d): undefined reference to `log'
/usr/bin/ld: complex.c:(.text+0x1255): undefined reference to `log1p'
/usr/bin/ld: complex.c:(.text+0x12f3): undefined reference to `log'
/usr/bin/ld: complex.c:(.text+0x130c): undefined reference to `log1p'
/usr/bin/ld: complex.c:(.text+0x1373): undefined reference to `hypot'
/usr/bin/ld: complex.c:(.text+0x1441): undefined reference to `atan2'
/usr/bin/ld: complex.c:(.text+0x1477): undefined reference to `atan2'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_sin':
complex.c:(.text+0x14b5): undefined reference to `sin'
/usr/bin/ld: complex.c:(.text+0x14f1): undefined reference to `sincos'
/usr/bin/ld: complex.c:(.text+0x1518): undefined reference to `cosh'
/usr/bin/ld: complex.c:(.text+0x1537): undefined reference to `sinh'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_cos':
complex.c:(.text+0x1585): undefined reference to `cos'
/usr/bin/ld: complex.c:(.text+0x15c1): undefined reference to `sincos'
/usr/bin/ld: complex.c:(.text+0x15e8): undefined reference to `cosh'
/usr/bin/ld: complex.c:(.text+0x160f): undefined reference to `sinh'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_tan':
complex.c:(.text+0x1654): undefined reference to `cos'
/usr/bin/ld: complex.c:(.text+0x16a3): undefined reference to `exp'
/usr/bin/ld: complex.c:(.text+0x16f3): undefined reference to `tanh'
/usr/bin/ld: complex.c:(.text+0x170b): undefined reference to `sin'
/usr/bin/ld: complex.c:(.text+0x1776): undefined reference to `sinh'
/usr/bin/ld: complex.c:(.text+0x179f): undefined reference to `sin'
/usr/bin/ld: complex.c:(.text+0x17c9): undefined reference to `sinh'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_sec':
complex.c:(.text+0x1814): undefined reference to `cos'
/usr/bin/ld: complex.c:(.text+0x1854): undefined reference to `hypot'
/usr/bin/ld: complex.c:(.text+0x18b6): undefined reference to `cosh'
/usr/bin/ld: complex.c:(.text+0x18d4): undefined reference to `sin'
/usr/bin/ld: complex.c:(.text+0x18f9): undefined reference to `sinh'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_csc':
complex.c:(.text+0x1944): undefined reference to `sin'
/usr/bin/ld: complex.c:(.text+0x1977): undefined reference to `hypot'
/usr/bin/ld: complex.c:(.text+0x19de): undefined reference to `cosh'
/usr/bin/ld: complex.c:(.text+0x19fc): undefined reference to `cos'
/usr/bin/ld: complex.c:(.text+0x1a10): undefined reference to `sinh'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_cot':
complex.c:(.text+0x1a59): undefined reference to `hypot'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_mod':
complex.c:(.text+0xe5): undefined reference to `hypot'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_arg':
complex.c:(.text+0x131): undefined reference to `atan2'
/usr/bin/ld: /usr/local/lib/libigraph.a(complex.c.o): in function `igraph_complex_abs':
complex.c:(.text+0x705): undefined reference to `hypot'
/usr/bin/ld: /usr/local/lib/libigraph.a(utils.c.o): in function `igraph_log2':
utils.c:(.text+0x29): undefined reference to `log'
/usr/bin/ld: /usr/local/lib/libigraph.a(utils.c.o): in function `igraph_log1p':
utils.c:(.text+0x389): undefined reference to `log'
collect2: error: ld returned 1 exit status

@shaily, before compiling your test program igraph_test, let us go back one step and check how you compiled igraph itself. You typically build and install it using the steps

mkdir build && cd build
cmake ..
cmake --build .
cmake --install .

By default it will generate a static library. You can install a shared library by doing cmake .. -DBUILD_SHARED_LIBS=ON instead of cmake ..

After you have done that, your approach below should work correctly

gcc igraph_test.c -I/usr/local/include/igraph -L/usr/local/lib -ligraph -o igraph_test

This is the same compilation command you used the first time. What I suggested to you was not to reinstall igraph, but to do one of two things:

Did you look in igraph.pc for the correct linking flags?

On my system they are -lm -lc++ -lxml2 -lz -lgmp -lblas -lcxsparse -lglpk -llapack -larpack. On yours they are very likely different, so you need to check igraph.pc. In particular, you likely need -lstdc++ instead of -lc++, and other differences are probable too.

This is what Vincent suggested as well. The documentation details how to build a shared library:

https://igraph.org/c/doc/igraph-Installation.html

If the documentation is unclear, feedback is welcome.

hi here is the output of cmake:

iit@iit-ROG-Strix-G532LWS-G532LWS:~/igraph-0.9.1/build$ cmake ..
-- Version number: 0.9.1
-- Disabling new dtags for testing to use RPATH to ensure the correct library is found.
  
-- -----[ Build configuration ]----
-- Version:                   0.9.1
-- CMake build type:        Release
-- Library type:             shared
  
-- ----------[ Features ]----------
-- GLPK for optimization:       yes
-- Reading GraphML files:       yes
-- Thread-local storage:         no
-- Link-time optimization:       no
  
-- --------[ Dependencies ]--------
-- ARPACK:                      yes
-- BISON:                       yes
-- BLAS:                        yes
-- CXSparse:                    yes
-- FLEX:                        yes
-- GLPK:                   vendored
-- GMP:                         yes
-- LAPACK:                      yes
-- LibXml2:                     yes
  
-- -----------[ Testing ]----------
-- Diff tool:                  diff
-- Sanitizers:                 none
-- Code coverage:                no
-- Verify 'finally' stack:       no
  
-- --------[ Documentation ]-------
-- HTML:                         no
-- PDF:                          no
  
-- igraph configured successfully.

-- Configuring done
-- Generating done
-- Build files have been written to: /home/iit/igraph-0.9.1/build

And igraph.pc file contains:

prefix=/home/iit
exec_prefix=/home/iit
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libigraph
Description: A library for creating and manipulating graphs
Version: 0.9.1
URL: https://igraph.org
Libs: -L${libdir} -ligraph
Libs.private: -lm -lstdc++ -lxml2 -lz -lgmp -lblas -lcxsparse -llapack -larpack
Cflags: -I${includedir}/igraph

The libraries are installed in the directory /home/iit/lib and the include files are installed in /home/iit/include, judging by your igraph.pc file. If you use

gcc igraph_test.c -I/home/iit/include/igraph -L/home/iit/lib -ligraph -o igraph_test

you should be able to compile correctly.

Note that you can also do this automatically using pkg-config as follows

gcc igraph_test.c `pkg-config --libs --cflags igraph` -o igraph_test

kudos it compiled but for running it shows:

iit@iit-ROG-Strix-G532LWS-G532LWS:~$ gcc igraph_test.c `pkg-config --libs --cflags igraph` -o igraph_test
iit@iit-ROG-Strix-G532LWS-G532LWS:~$ ./igraph_test 
./igraph_test: error while loading shared libraries: libigraph.so.0: cannot open shared object file: No such file or directory
iit@iit-ROG-Strix-G532LWS-G532LWS:~$

Great! Almost there!

If you are using dynamic libraries (i.e. shared libraries) you need to make sure that the library is found when you run the executable. On Linux you do that by setting the LD_LIBRARY_PATH environment variable. You can for example do

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/iit/lib

You can also set this environment variable permanently, but this depends a bit on your system. You can for example set it in your ~/.bashrc file.

For this specific problem, the advice from the tutorial (setting LD_LIBRARY_PATH) should work on Linux (not on other platforms):

https://igraph.org/c/doc/igraph-Tutorial.html#tut-lesson-1

Regarding pkg-config, the tutorial is now inaccurate.

If you built igraph as a static library, the correct way to retrieve flags is

pkg-config --static --libs --cflags igraph

In order for pkg-config to find the igraph.pc file, the directory containing this file must be added to the PKG_CONFIG_PATH environment variable. pkg-config will itself tell you this if it fails to locate igraph.pc.

You can also retrieve the linking flags manually from the Libs.private section of the igraph.pc file. Note that these are necessary only when igraph was built as a static library.

If you built igraph as a shared library, the correct flags can be retrieved using

pkg-config --libs --cflags igraph

We are looking to make this procedure easier for the next version, and to have a beginner friendly and up-to-date tutorial in the documentation.

It’s working now.
By using this command line - sudo apt-get install libnlopt0 that library error resolved.

Thank you for your support.

It’s working now.
By using this command line - sudo apt-get install libnlopt0 that library error resolved.

Thank you for your support.

Can you clarify which problem was resolved by installing libnlopt0? This library has no relation whatsoever to igraph, and is not needed for using igraph.