1

I am learning C++ and GSL(GNU Scientific Library). I try to use vscode to build a simple program but I got this error.

Undefined symbols for architecture x86_64:
  "_gsl_rng_types_setup", referenced from:
    _main in Playground-0f069f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

My code is this

#include <gsl/gsl_rng.h>
#include <iostream>
#include <stdio.h>
#include <stddef.h>
#include <gsl/gsl_sort_double.h>
#include <gsl/gsl_matrix.h>

int main(){
    const gsl_rng_type **t, **t0;
    t0 = gsl_rng_types_setup (); 
    for (t = t0; *t != 0; t++) {
        std::cout<<(*t)->name; 
    }
}

And the task.json is

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "args": ["-o", "Playground", "Playground.cpp"],
    "showOutput": "always"
}

Any help much appreciated!

Molin.L
  • 113
  • 6
  • 1
    You likely need to link against `gsl` when compiling, e.g. add a `-lgsl -lgslcblas -lm` together with correct path to `"args"`, see https://www.gnu.org/software/gsl/manual/html_node/Linking-programs-with-the-library.html#Linking-programs-with-the-library. – Holt Apr 13 '17 at 12:49
  • @Holt Many thanks! – Molin.L Apr 15 '17 at 05:51
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan Apr 16 '17 at 09:49

0 Answers0