【发布时间】:2015-03-06 23:47:08
【问题描述】:
我正在将代码从 Visual Studio 移植到 Mingw GCC。该组件在 Visual Studio 中运行良好,但 Mingw GCC 抱怨未定义对函数的引用。我已经隔离了这种情况并在这里写下代码
文件:Rng.h
#pragma once
#ifdef RNG_EXPORTS
#define RNG_API __declspec(dllexport)
#else
#define RNG_API __declspec(dllimport)
#endif
RNG_API unsigned long GetRandom(unsigned long range);
文件:Rng.cpp
#include "Rng.h"
#include "RngKiss.h"
static TRngFile gRngFile;
unsigned long GetRandom(unsigned long range)
{
gRngFile.generate_rnd(); //Linker Error : Undefined Reference to function.
....
}
文件:RngKiss.h
#ifndef __RNGKISS_H__
#define __RNGKISS_H__
#ifndef ULONG
typedef unsigned long ULONG;
#endif //ULONG
typedef struct
{
ULONG w, x, y, z;
} TRngRecord;
typedef struct
{
TRngRecord current, seed;
ULONG generate_rnd(void);
} TRngFile;
#endif
文件:RngKiss.cpp
#include "RngKiss.h"
ULONG TRngFile::generate_rnd(void)
{
ULONG d;
return d;
}
这是我的输出。
g++.exe -L..\..\..\mingw64\lib\boost -o bin\Debug\TestCodeBlocks.exe obj\Debug\main.o obj\Debug\Rng.o obj\Debug\RngKiss.o
obj\Debug\Rng.o: In function `GetRandom(unsigned long)':
C:/Users/admin/TestCodeBlocks/Rng.cpp:8: undefined reference to `TRngFile::generate_rnd()'
collect2.exe: error: ld returned 1 exit status
关于我为什么会收到此链接器错误以及如何解决它的任何建议?
【问题讨论】:
标签: c++ c visual-studio gcc