这里有一些简化的代码来演示我遇到的问题.
我有一个模板函数,我只希望编译某些固定的实例.
函数声明是:
// *** template.h ***
int square (int x);
double square (double x);
定义是:
// *** template.cpp ***
#include "template.h"
// (template definition unusually in a code rather than header file)
template <typename T>
T square (T x)
{
    return x*x;
}
// explicit instantiations
template int square (int x);
template float square (float x);
并且,示例用法是:
// *** main.cpp ***
#include <iostream>
using namespace std;
#include "template.h"
int main (void)
{
    cout << square(2) << endl;
    cout << …在2年的java之后,我在3周前开始学习c ++.它看起来如此不同,但即将到达那里.我的讲师是一个可爱的家伙,但任何时候我问一个问题,为什么这样或那样的东西.他只是回答"因为它是".
下面的代码中有很多评论带有一些随机问题,但主要问题是我得到两个构建错误,一个说arraytotal尚未初始化(即使我找到了它的值),另一个说是外部引用在主要.
有人会介意阅读代码并回答一些评论,也许我可能遇到的整体问题?
#include<string>
#include<fstream>
#include<ostream>
using namespace std;
//double decimals[5] ={2,4,6,8,10};
const int arraySize = 5;
// does an arraySize have to be const always? is it so it doesnt channge after the array has been created?
//double decimals[arraySize];
/*
   this array is being created in the function averageN() but why?
   cant i just create it up top and reference it in?
 */
// why do you have to write the name of the function up here before …我是C++的新手,所以我下载了一个示例C++程序.示例程序在编译时似乎遇到以下错误: -
Error   22  error LNK2019: unresolved external symbol _acsEnumServerNames@12    referenced in function "protected: virtual int __thiscall COpenTsrv::OnInitDialog(void)" (?OnInitDialog@COpenTsrv@@MAEHXZ)  Opentsrv.obj    
我将它追溯到推荐的功能,但我不知道它有什么问题吗?
BOOL COpenTsrv::OnInitDialog() 
{
CDialog::OnInitDialog();
CenterWindow();
acsEnumServerNames(ST_CSTA, AddToList, (unsigned long) (CComboBox*)&m_TserverListControl);
UpdateData(FALSE);
以下是构建日志.显然还有其他错误,但想从第一个开始.
1>Generating Code...
1>Compiling resources...
1>Compiling manifest to resources...
1>Linking...
1>Opentsrv.obj : error LNK2019: unresolved external symbol _acsEnumServerNames@12  referenced in function "protected: virtual int __thiscall COpenTsrv::OnInitDialog(void)" (? OnInitDialog@COpenTsrv@@MAEHXZ)
1>Opentsrv.obj : error LNK2019: unresolved external symbol _acsQueryAuthInfo@8 referenced in function "protected: void __thiscall COpenTsrv::OnSelchangeTserverlist(void)" (?OnSelchangeTserverlist@COpenTsrv@@IAEXXZ)
1>Opentsrv.obj : error LNK2019: …我正在尝试在Visual Studio 2010 Ultimate项目中使用Q_OBJECT宏,它给了我未解决的外部错误:
1>Application.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall MyButton::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MyButton@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>Application.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall MyButton::qt_metacast(char const *)" (?qt_metacast@MyButton@@UAEPAXPBD@Z)
1>Application.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MyButton::metaObject(void)const " (?metaObject@MyButton@@UBEPBUQMetaObject@@XZ)
我有一个使用QMaker的类似项目,并通过干净的项目和重新运行qmake来解决它.问题是,VS中没有"Qmake"按钮!
我读过很多像这样的文章并完成了他们告诉我的所有内容.虽然它没有真正帮助,因为我已经有一些.cpp和一些头文件的现有项目,我想避免创建.pro文件并将代码移入其中.
我已经安装了VS Qt插件,它在VS面板上给了我新的酷"Qt"按钮,虽然没有帮助解决未解决的外部(可能我不知道如何正确使用它).
我在我的Application.h文件(唯一一个有Q_OBJECT)的VS中运行了通过自定义构建工具的moc,但是仍然没有帮助:
C:\Utilities\QtSDK\Desktop\Qt\4.8.1\msvc2010\bin\moc Application.h -o tmp\moc\moc_Application.cpp
什么可能导致我的问题,我该如何解决?
我目前在编译代码时收到以下错误:
错误LNK2019:无法解析的外部符号“ public:void __thiscall Agent :: printSelf(void)”(?printSelf @ Agent @@ QAEXXZ)在函数“ public:void __thiscall World :: processMouse(int,int,int,int)”中引用(?processMouse @ World @@ QAEXHHHH @ Z)World.obj
这是我的代码
Agent.h:
class Agent
{
public:
    Agent();
void printSelf();
Agent.cpp:
void Agent::printSelf()
{
printf("Agent species=%i\n", species);
for (int i=0;i<mutations.size();i++) {
    cout << mutations[i];
}
}
GLView.cpp:
void GLView::processMouse(int button, int state, int x, int y)
{
if(world->isDebug()) printf("MOUSE EVENT: button=%i state=%i x=%i y=%i\n", button, state, x, y);
if(button==0){
    int wx= (int) ((x-conf::WWIDTH/2)/scalemult-xtranslate);
    int wy= (int) ((y-conf::WHEIGHT/2)/scalemult-ytranslate);
    world->processMouse(button, state, …我正在尝试在我的 Qt 应用程序中使用 Crypto++ 库。
Qt 版本为 5.3.0 在 Windows 8.1 上运行 VS2013 编译
用 VS2013 编译的 Crypto++ Lib
这是我的 .pro 文件中链接 lib 的部分
win32: LIBS += -L$$PWD/cryptopp562/Win32/DLL_Output/Release/ -lcryptopp
INCLUDEPATH += $$PWD/cryptopp562
DEPENDPATH += $$PWD/cryptopp562
一切似乎都很好。但是我有两个问题。
我无法编译调试版本。我认为这是因为我有 .lib 文件的发布版本
当我尝试编译我的应用程序时,出现以下错误
crypto.obj:-1: 错误: LNK2019: 未解析的外部符号 "class std::basic_string,class std::allocator > const CryptoPP::DEFAULT_CHANNEL" (?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@ D@std@@V?$allocator@D@2@@std@@B) 在函数“public: virtual bool __thiscall CryptoPP::Unflushable::Flush(bool,int,bool)”中引用 (?Flush@?$ Unflushable@VFilter@CryptoPP@@@CryptoPP@@UAE_N_NH0@Z)
我收到两个这样的错误,我认为这是由于两个调用 lib 的函数没有被编译。
我的观察:
似乎我正在链接到正确的静态库,即 libcrypt.lib,并且我使用了 dumpbin 实用程序来确保错误指定的缺失符号存在于 lib 文件中。
看来,虽然我在 .pro 文件中指定了一些 lib 没有被项目引用的方式。我已将以下行放在我的 .pro 文件中以引用静态库
win32:LIBS += -L$$PWD/cryptopp562/Win32/Output/Release/-lcryptlib …
我的目标是在 Visual Studio 中使用 Rest API。我从https://github.com/Microsoft/vcpkg下载了 C++ 工具 vcpkg并按照https://github.com/Microsoft/cpprestsdk上的说明安装了 cpprestsdk。那工作得很好。
然后,在 Visual Studio 的解决方案资源管理器的属性中,我将 vcpkg 文件夹中的以下路径包含到“VCC++ 目录->包含目录”中:
vcpkg-master\vcpkg-master\buildtrees\cpprestsdk\src\v2.10.2-718a4e55e9\Release\include\cpprest
vcpkg-master\vcpkg-master\buildtrees\cpprestsdk\src\v2.10.2-718a4e55e9\Release\include
vcpkg-master\vcpkg-master\buildtrees\cpprestsdk\src\v2.10.2-718a4e55e9\Release\include\pplx
然后我运行我的代码并出现以下错误:
LNK2001 unresolved external symbols (32个这样的错误)
我用谷歌搜索并被告知将相应的“.lib”文件包含到“属性->链接器->输入->附加依赖项”中,并将相应的“.dll”文件的路径包含到“属性->链接器”中->General->Additional Library Directories”,我所做的。
现在,再次运行代码,只出现以下错误:
code execution cannot proceed because cpprest_2_10.dll was not found. Reinstalling the program may fix the problem,
尽管“cpprest_2_10.dll”在我之前包含的路径中。
我不知道问题是什么。提前感谢您的时间。
我试图从这个特定链接https://www.youtube.com/watch?v=PTQkCRxr6lk&t=194s下载 SDL 库。但是我偶然发现了一个“致命错误”,我不知道该怎么做才能解决它。
这是我得到的错误:
1>------ Build started: Project: SDL2, Configuration: Release x64 ------
2>------ Skipped Build: Project: uninstall, Configuration: Release x64 ------
2>Project not selected to build for this solution configuration 
1>   Creating library D:/Media/Downloads/SDL2-2.0.10/Build/Release/SDL2.lib and object D:/Media/Downloads/SDL2-2.0.10/Build/Release/SDL2.exp
1>SDL_string.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_vsnprintf_REAL
1>D:\Media\Downloads\SDL2-2.0.10\Build\Release\SDL2.dll : fatal error LNK1120: 1 unresolved externals
1>Done building project "SDL2.vcxproj" -- FAILED.
3>------ Skipped Build: Project: INSTALL, Configuration: Release x64 ------
3>Project not selected to build …我正在编写一些代码,我定义了以下基类.
class Chorus{
  public:
    //Destructor
    virtual ~Chorus();
    //callback function
    virtual int callback( void *outputBuffer, void *notUsed, unsigned int 
       nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData );
    virtual void initializeDelayBuffer(void);
    virtual void destroyDelayBuffer(void);
};
我想将它用作基类,而不是实际上对它自己做任何事情.所以我有两个单独的类,它们来自这个类Chorus.我想这样做只是简单地提供一些基本约束,以确定任何派生的Chorus类必须被认为在我的程序中可用.
当我构建我的项目(Visual Studio 2008)时,我在此Chorus类的所有虚函数上得到了未解析的外部符号错误.我猜这是典型的错误,我没有做出这些函数的前向声明.但是,由于它们是虚拟的,我不希望它们实际被定义为在导出类中定义之前做任何事情,我该怎么做才能解决这个问题?
我正在尝试解决未解决的外部问题(link2019 错误)。StackOverflow 上有很多关于这个问题的帖子,但要么我不理解这个错误,要么我对它视而不见。
该错误是由我的generate_maze函数引起的(特别是由rand_neighbor()调用引起的,对吧?)但我的理解是这些都已“解决”。
我稍微截断了代码,因为它非常冗长。我希望这是合适的。
void generate_maze (Vector<int> &coords, Grid<bool> &included, Maze &m);
int main() {
    Grid<bool> included = initialize_grid();
    Vector <int> coords = rand_coords();
    Vector <int> current_point = coords;
    generate_maze(coords, included, m);
    return 0;
}
void generate_maze (Vector<int> &coords, Grid<bool> &included,  Maze &m) {
    while (gridIsTrue == false) {
    Vector<int> neighbor = rand_neighbor(coords, included);
    pointT neighborpoint = {neighbor[0], neighbor[1]};
    pointT current_point = {coords[0], coords[1]};
    if (included.get(neighbor[0], neighbor[1]) == false) {m.setWall(current_point, neighborpoint, false); included.set(neighbor[0], neighbor[1], true); current_point = neighborpoint;}
    } …