标签: undefined-reference

从C程序调用C++函数

如何从C程序调用C++函数,是否可能?,如果是,我该怎么办呢?谢谢.

makefile scons undefined-reference

1
推荐指数
1
解决办法
336
查看次数

boost :: program_options未定义的引用

我使用的是ubuntu 10.04和libboost1.40.

ls -l /usr/lib | grep boost_pro
    -rw-r--r--  1 root root   640800 2010-04-01 05:19 libboost_program_options.a
    lrwxrwxrwx  1 root root       26 2011-11-03 22:40 libboost_program_options-mt.a ->                  libboost_program_options.a
    lrwxrwxrwx  1 root root       34 2011-11-03 22:40 libboost_program_options-mt.so ->                libboost_program_options.so.1.40.0
    lrwxrwxrwx  1 root root       34 2011-11-03 22:40 libboost_program_options.so ->    libboost_program_options.so.1.40.0
    -rw-r--r--  1 root root   289336 2010-04-01 05:19 libboost_program_options.so.1.40.0
Run Code Online (Sandbox Code Playgroud)

这是main.cpp(仅用于测试)

     #include <string> 
#include <iostream> 
#include <boost/date_time/gregorian/gregorian.hpp> 
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/program_options/options_description.hpp>
//--------------------------------------------------------------------- 
int main(int argc,char** argv) 
{ 
 boost::gregorian::date now(boost::gregorian::day_clock::local_day());
 //is works fine 
 std::cout<<boost::gregorian::to_iso_string(now)<<std::endl;
 boost::program_options::options_description a; //but …
Run Code Online (Sandbox Code Playgroud)

c++ boost linker-errors undefined-reference ubuntu-10.04

1
推荐指数
1
解决办法
4379
查看次数

javascript在数组中发出未定义的变量

有人可以告诉我这段代码有什么问题吗?scrns[i]虽然Chrome仍然在鼠标悬停时运行代码,但Chrome和Firefox都表示未定义.

function nextPrev() {
  if (!document.getElementsByClassName) return false;
  var scrns = document.getElementsByClassName('scrn');
  for (var i=0; i<=scrns.length; i++) {
    // console.log(i);
    scrns[i].onmouseover = function() {
      // console.log('foo');
    }
  }
}
window.onload = nextPrev();
Run Code Online (Sandbox Code Playgroud)

我已经测试了for循环是否正常工作,并试图以我知道的各种方式确定问题的来源.我甚至看了一下我前一本书中的一个例子,并且无法理解为什么scrns[i]不定义.

任何帮助非常感谢!

javascript arrays undefined-reference

1
推荐指数
2
解决办法
264
查看次数

使用gcc未定义引用`__gxx_personality_v0'

可能重复:
__gxx_personality_v0是什么?

我已经在编译C++代码的上下文中看到了这个问题.但是我要编译 C代码并继续收到此错误.我被禁止使用"-lstdc ++"作为解决此gcc问题的方法.如何更改我的代码以使其正常工作以及为什么会出现此错误?

我的简化代码:

//this is main.cpp
#include <stdio.h>
int main()
{
    char ch[3];
    ch[0] = getc(stdin);
    ch[1] = getc(stdin);
    ch[2] = '\0';
    printf("%s\n", ch);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的编译命令是:

gcc main.cpp
Run Code Online (Sandbox Code Playgroud)

c gcc undefined-reference

1
推荐指数
1
解决办法
2万
查看次数

C编程 - "文件中引用的未定义符号"

我正在尝试编写一个程序来估算pi.它基本上取0.00和1.00之间的随机点,并将它们与圆的界限进行比较,圆内点与总点的比率应接近pi(非常快速的解释,规范深入更多).

但是,在使用gcc进行编译时出现以下错误:

Undefined                       first referenced
symbol                          in file
pow                             /var/tmp//cc6gSbfE.o
ld: fatal: symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

发生了什么事?我以前从未见过这个错误,我不知道它为什么会出现.这是我的代码(虽然我没有完全测试它,因为我无法通过错误):

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
    float x, y;
    float coordSquared;
    float coordRoot;
    float ratio;
    int n;
    int count;
    int i;

    printf("Enter number of points: ");
    scanf("%d", &n);

    srand(time(0));

    for (i = 0; i < n; i++) {
        x = rand();
        y = rand();

        coordSquared = pow(x, 2) + pow(y, …
Run Code Online (Sandbox Code Playgroud)

c linker-errors undefined-reference

1
推荐指数
1
解决办法
2万
查看次数

waf在链接时:"未定义引用"错误

所以我在最近2个小时内一直在敲打这个编译器错误,并认为我会在这里发布代码,看看是否有人可以解释我的错误.

我已经删除了所有不相关的位以留下一个简单的最小程序(如下所示),据我所知,它应该编译并运行.如果我纪念,但我看不出什么是错误的调用testFunc in main然后一切编译并运行正常.然而,通过调用testFunc,我得到以下内容:

$ ./waf -v --run abr-tool
Waf: Entering directory `/home/conor/workspace/msc/AdaptiveIPTV/Software/conor/ns3/ns-3.15/build'
[1665/1822] cxxprogram: build/src/abr-tools/examples/abr-tool.cc.4.o -> build/src/abr-tools/ns3.15-abr-tool-debug
19:04:19 runner ['/usr/bin/g++', '-L/usr/lib', '-lboost_iostreams', '-L/usr/lib', '-lboost_iostreams', '-pthread', 'src/abr-tools/examples/abr-tool.cc.4.o', '-o', '/home/conor/workspace/msc/AdaptiveIPTV/Software/conor/ns3/ns-3.15/build/src/abr-tools/ns3.15-abr-tool-debug', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-Wl,--no-as-needed', '-L.', '-L.', '-L.', '-L.', '-L.', '-L.', '-lns3.15-point-to-point-debug', '-lns3.15-internet-debug', '-lns3.15-mpi-debug', '-lns3.15-bridge-debug', '-lns3.15-network-debug', '-lns3.15-core-debug', '-lrt']
src/abr-tools/examples/abr-tool.cc.4.o: In function `main':
/home/conor/workspace/msc/AdaptiveIPTV/Software/conor/ns3/ns-3.15/build/../src/abr-tools/examples/abr-tool.cc:7: undefined reference to `testFunc()'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,下面的代码是作为一个更大的项目的一部分构建的,我知道错误可能来自该构建过程而不是我的代码的问题,但无论哪种方式我都遇到了一些问题在我对这里发生的事情的理解中.我正在学习c ++,并且说实话我觉得自己没有足够的经验甚至只是自己编译这段代码而且能够说"那应该肯定有用,但它没有",这就是为什么我像这样呈现它.

另外几点可能是相关的:

  • 我可以使用来自abr-tools.cc的abr-helper.h中定义的宏,当我将abr-tools.cc放在与abr-helper.h相同的文件夹中时,问题仍然存在,只需使用'#include'abr-helper .H"'.

  • 原始错误是一样的,但对于abr-helper.h中定义的一堆其他东西并在abr-tools.cc中使用

我要感谢大家提供的任何帮助,提前谢谢.

ABR-helper.h:

#ifndef ABR_HELPER_H
#define ABR_HELPER_H
#include <iostream>

void testFunc();

#endif /* ABR_HELPER_H */ …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors waf undefined-reference

1
推荐指数
1
解决办法
1734
查看次数

C++未定义的模板类方法引用

我总是得到

未定义的引用`Graph :: InsertVertex(std :: string)'

如果我编译我的项目!有什么提示他为什么不能解决这个问题?(所有文件都在netbeans项目文件夹中)

// main.cpp

#include <cstdlib>
#include <string>
#include "Graph.h"

using namespace std;

int main(int argc, char** argv)
{
    Graph<string> *graph = new Graph<string>(); // <--- ERROR

    graph->InsertVertex("A");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

// Node.h

#include <iostream>
#include "Graph.h"

template<class T> 
class Node
{   

friend class Graph;    

public:
    Node(T val)
    {
        this->data = val;
        this->vertList = NULL;
        this->next = NULL;
    }

    Node(const Node& orig);
    virtual ~Node();

private:
    T data;
    Node<T> *vertList;
    Node<T> *next;
    int status;

};
Run Code Online (Sandbox Code Playgroud)

// …

c++ templates undefined-reference

1
推荐指数
2
解决办法
2万
查看次数

C++中的多重定义错误,使用头文件

我刚接触C++编程,但有一些Java经验.我创建了一个非常基本的类Dog.cpp及其头文件Dog.hpp.Netbeans不会构建项目,给我一个错误,说明构造函数和getAge函数的多个定义.就我而言,我已经在头文件中声明了构造函数和函数,并在类文件中定义它们.我哪里出错了?

提前致谢!

Dog.hpp:

#include <iostream>
using namespace std;
class Dog 
{
public:
    Dog(int someAge);           // Constructor
    ~Dog();                     // Destructor
    int getAge() const;         // function prototype
private:
    int itsAge;                 // age variable

};
Run Code Online (Sandbox Code Playgroud)

Dog.cpp:

#include "Dog.hpp"
using namespace std;


Dog::Dog(int anAge) 
{
    cout << "Dog created \n";
}

int Dog::getAge() const
{
    return itsAge;
}
Run Code Online (Sandbox Code Playgroud)

**main.cpp

#include <iostream>
#include "Dog.cpp"

int main() 
{
    Dog aDog(5);
    cout << aDog.getAge();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Netbeans输出:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory …
Run Code Online (Sandbox Code Playgroud)

c++ linker-errors undefined-reference

1
推荐指数
1
解决办法
1168
查看次数

为什么我会得到'未定义或空引用'中环?

我正在使用VBS创建一个JavaScript数组.HTML页面上生成的代码会产生错误(如下面代码中所示).为什么在第三次分配时会出现此错误?(我是一个相对初学者).

<script type="text/javascript">

    var myArray = [[],[]];

    myArray[0][0] = "3";
    myArray[1][0] = "1";
    myArray[2][0] = "2";
    **Unable to set property '0' of undefined or null reference**
    myArray[3][0] = "4";

</script>
Run Code Online (Sandbox Code Playgroud)

javascript undefined-reference

1
推荐指数
1
解决办法
34
查看次数

无法编译Hello World

对不起,如果这是一个重复的问题,但我找不到有效的答案.

我很长一段时间以来第一次写了一个Hello World C程序.我相当肯定代码是正确的,但它不会编译.

运行MAC OS 10.13.6,我上周刚刚下载了XCode.该程序使用编译成目标文件

cc -c test.c -o test.o
Run Code Online (Sandbox Code Playgroud)

没问题.但是,我无法使用创建可执行文件

cc test.o -o test
Run Code Online (Sandbox Code Playgroud)

这是代码:

#include <stdio.h>
int Main()
{
    printf("Hello World");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我去创建可执行文件时,我得到了

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
Run Code Online (Sandbox Code Playgroud)

我猜我需要添加一些编译器标志,但无法弄清楚哪些.

c macos linker-errors undefined-reference undefined-symbol

1
推荐指数
1
解决办法
97
查看次数