我是Visual Studio的新手,所以如果这是一个基本问题我会道歉.我有一个包含许多项目的解决方案.在项目A中,我有一组预先存在的文件,我添加了一个新类.项目B使用项目A中新类编写的功能.首先构建项目A,生成.lib文件,并将.lib文件链接到项目B.但是,当我去创建.lib文件时Project BI遇到链接错误,引用我添加的项目A中的新功能.使用'dumpbin'命令和项目A生成的.lib文件,我注意到我添加的函数的符号不存在.但是,在项目A中编译新类之后创建的.obj文件确实包含这些符号.知道为什么那些符号不会出现在Project A的.lib文件中吗?
在SO上遇到这两个链接器错误的问题后,我再次使用它们.然而,这一次来源似乎在于另一点.
编译器错误表明它找不到带签名的函数""public: unsigned int __thiscall MyClass::myFunction<unsigned int>(int)const ".
但是,将内容移动myClass.cpp到main.cpp工作中.不知道为什么(所有其他内容myClass.cpp都没有这个问题.(其他功能都没有模板化).
myClass.h
#ifndef X
#define X
class MyClass {
public:
template<class T>
T myFunction (int someArgument) const;
};
#endif
Run Code Online (Sandbox Code Playgroud)
myClass.cpp
#include "myClass.h"
template<class T>
T MyClass::myFunction (int someArgument) const {
return T();
}
Run Code Online (Sandbox Code Playgroud)
main.cpp
#include "myClass.h"
int main () {
MyClass a();
a.myFunction<unsigned int>(42);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这个问题?
//cstack.h
# ifndef _STACK_H__
#define _STACK_H__
#include<iostream>
#include<vector>
template< class Type ,int Size = 3>
class cStack
{
Type *m_array;
int m_Top;
int m_Size;
public:
cStack();
cStack(const Type&);
cStack(const cStack<Type,Size> &);
int GetTop()const;
bool Is_Full()const;
bool Is_Empty()const;
void InsertValue(const Type&);
void RemeoveValue();
void show();
~cStack();
friend std::ostream& operator <<(std::ostream &, const cStack<Type,Size> &);
};
// iam writing only one function defination because linking is because of this function
template< class Type,int Size >
std::ostream& operator << ( std::ostream &os, const …Run Code Online (Sandbox Code Playgroud) 我希望我能对类的静态变量做一些澄清.
例如:我有两个不同的类,它们执行完全不同的功能,alpha和beta.在alpha中,我声明了一个beta类型的静态变量,所以它看起来像这样:
//alpha.h
#pragma once
#include <iostream>
#include "beta.h"
class alpha{
public:
alpha(){
}
static beta var;
void func(){
var.setX(3);
}
void output(){
}
};
//beta.h
#pragma once
#include <iostream>
using namespace std;
class beta{
public:
int x;
char y;
beta(){
x = 0;
y = ' ';
}
void setX(int _X){
x = _X;
}
};
//main.cpp
#include <iostream>
#include <iomanip>
#include "alpha.h"
using namespace std;
int main(){
alpha x, y, z;
x.func();
}
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试编译它时,我得到一个未解决的外部错误:
错误LNK2001:未解析的外部符号"public:static class beta alpha …
我试图在C++中将函数作为参数传递.我一直收到LNK2019未解决的外部符号错误.
我已经读过这些,并且已经修复了这些,但我无法弄清楚我在这里做错了什么.
我的显示函数中的TreeItemType引用似乎发生了错误.
include "PhoneBook.h"
include "PhoneEntry.h"
include "bst.h"
using namespace std;
using namespace p04NS;
void display(TreeItemType& item);
int main() {
PhoneEntry test = PhoneEntry("first", "last", "618-580-0680");
bst * tree = new bst();
TreeItemType foo = TreeItemType(); // test type reference, no error
tree->insert(test);
tree->inorder(display);
system("pause");
return 0;
}
void display(TreeItemType& item){
cout << "hello worlds!";
}
Run Code Online (Sandbox Code Playgroud)
TreeItemType typedef在此处定义.
namespace p04NS {
typedef PhoneEntry TreeItemType;
typedef string KeyType;
// Pointer to a function that can be used to …Run Code Online (Sandbox Code Playgroud) 我自己编译了boost库,使用g ++ 4.8编译成功完成.一切都在〜/ bin/boost中.编译后,所有文件都位于/ Users/$(USER)/ bin/boost/stage/lib /
以下必要的部分:
CC=g++-4.8
LD=g++-4.8
BOOST_LIB_PATH=/Users/$(USER)/bin/boost/stage/lib/
BOOST_HEADER_PATH=/Users/$(USER)/bin/boost/
LFLAGS=-L$(BOOST_LIB_PATH) -lboost_thread
release: $(OBJ)
$(LD) $(OBJ) obj/main.o $(LFLAGS) -o $(RELEASE_NAME)
Run Code Online (Sandbox Code Playgroud)
编译期间一切正常,但链接过程失败.基本上所有错误看起来都一样:
ndefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)
Run Code Online (Sandbox Code Playgroud)
我已经读过: 尝试使用Boost.Filesystem然而它似乎没有链接? C++/Boost:示例中未定义的符号? 和许多其他人但仍然没有找到解决方案.
我不知道问题在哪里,我已经改变了链接的顺序,我尝试直接链接线程库,但我仍然得到相同的结果.在mac os x 10.8.4下编译https://github.com/dbedla/snake-cpp11期间出现问题(我必须修改makefile)
我将不胜感激任何有关如何解决问题的建议.
对不起我的英语不好 :(
我是OpenCV的新手,我尝试了一些故障排除,试图让我的标题编译但继续遇到链接器错误.
这是我想要运行的代码:
//Visual Studio
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>
//LabView
//#include <NIVision.h>
//Opencv
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
1>------ Rebuild All started: Project: Veni_Main, Configuration: Debug Win32 ------
1> stdafx.cpp
1> Veni_Main.cpp
1>c:\opencv\build\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen' …Run Code Online (Sandbox Code Playgroud) 嘿伙计们,我前几天问过一些我无法解决的c ++代码问题.我接受了每个人关于如何用c ++创建对象的建议,但现在我得到了未定义的引用错误.我正在使用最新的代码块版本并使用它来编译.我已经读过这是因为在编译过程中没有链接某些文件,这意味着我已经在头文件中定义了类但没有在代码中定义,这让我感到困惑,因为从我的理解(教授示例)我宣布对象.
头文件MathObject.h
class MathObject{
private:
int num1;
int num2;
public:
int sum();
MathObject(int n, int m);
};
Run Code Online (Sandbox Code Playgroud)
MathObject文件MathObject.cpp
#include <iostream>
#include "MathObject.h"
using namespace std;
MathObject :: MathObject(int n, int m){
num1 = n;
num2 = m;
}
int MathObject :: sum(){
return num1+num2;
}
Run Code Online (Sandbox Code Playgroud)
主文件
#include <iostream>
#include "MathObject.h"
using namespace std;
int main(int args, char *argv[]){
MathObject *mo = new MathObject(3,4);
int sum = mo -> sum();
MathObject mo2(3,4);
//cout << sum << endl;
return 0; …Run Code Online (Sandbox Code Playgroud) 我试图从Swift调用一个简单的C++函数,但我得到Apple Mach-O链接器错误:


我的Sample.h文件(C++):
#if __cplusplus
extern "C" {
#endif
int getOne();
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
我的Sample.cpp文件:
#include <stdio.h>
int getOne()
{
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我的桥头:
#include "Sample.h"
Run Code Online (Sandbox Code Playgroud)
我试图将函数调用如下:
println(getOne())
Run Code Online (Sandbox Code Playgroud)
笔记:
我确实将C++库添加到项目和构建库(构建阶段),我尝试使用Xcode 6.2(Swift 1.1)和Xcode 6.3(beta Swift 1.2),并且出现相同的错误.
我确实在构建设置中添加了桥接头.
我已经阅读了一些关于在Obj-c中包装我的C++代码的内容,但我还没有完全掌握它.
任何帮助表示赞赏.
昨天我将MacBook Pro更新为El Capitan.我有Xcode 6.1更新Xcode不会打开,Xcode 6.1但我Xcode 7.0.1强行下载我不想升级,但我被迫.我用Objective-C创建了我的应用程序.提交给苹果,它目前正在"等待开发者发布".
我想改变一些东西,但现在无处不在,Xcode 7.0.1我得到了一个我从未收到过的错误Xcode 6.1.
ld: '/Users/markjak/Desktop/Stick Down copy/Leap Up/LibAdapterIAd- 1.0.0/libAdapterIAd.a(GADMAdapterIAdInterstitial.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我如何做Xcode 7.0.1要我做的事情?