>  Q&A  >  본문

c++ - vscode如何正确地link programs with library?

刚刚开始用vscode,在build的过程中出现了

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

这样的错误,
我的代码是

#include <gsl/gsl_rng.h>
#include <iostream>
#include <stddef.h>


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

按理我的library就在默认的位置(/usr/local/lib)不会出现这个问题吧。。
所以想求个解决方案,不胜感激!

怪我咯怪我咯2765일 전606

모든 응답(1)나는 대답할 것이다

  • 大家讲道理

    大家讲道理2017-04-17 15:41:04

    最后我用terminal解决了这个问题

    g++ -L/usr/local/lib -o "Playground" "Playground.cpp"
    

    这不是非常方便。。如果有更好的解决方法非常欢迎,比如修改task.json

    회신하다
    0
  • 취소회신하다