Problem in building EXAMPLE

For developers writing C++, Fortran, Java, code who have questions or comments to make.

Moderators: silvia, selimgunay, Moderators

Post Reply
kawakaze
Posts: 1
Joined: Sat Apr 09, 2016 5:01 am

Problem in building EXAMPLE

Post by kawakaze » Sat Apr 09, 2016 5:15 am

Hey everyone.Now I have some problem in building my own examples

my environment:win7(64 bit),vs2008,the version of opensees is 2.3.0

Now it's OK to build opensees.exe and it works.

But I'm trying to code by C++ instead of using tcl.

I open a new project and code an easy example as follows :

// standard C++ includes

#include <stdlib.h>

#include <OPS_Globals.h>
#include <StandardStream.h>

#include <ArrayOfTaggedObjects.h>

// includes for the domain classes
#include <Domain.h>
#include <Node.h>
#include <Truss.h>
#include <ElasticMaterial.h>
#include <SP_Constraint.h>
#include <LoadPattern.h>
#include <LinearSeries.h>
#include <NodalLoad.h>

// includes for the analysis classes
#include <StaticAnalysis.h>
#include <AnalysisModel.h>
#include <Linear.h>
#include <PenaltyConstraintHandler.h>
#include <DOF_Numberer.h>
#include <RCM.h>
#include <LoadControl.h>
#include <BandSPDLinSOE.h>
#include <BandSPDLinLapackSolver.h>


// init the global variabled defined in OPS_Globals.h
StandardStream sserr;
OPS_Stream *opserrPtr = &sserr;

double ops_Dt = 0;
// Domain *ops_TheActiveDomain = 0;
Element *ops_TheActiveElement = 0;



// main routine
int main(int argc, char **argv)
{
//
// now create a domain and a modelbuilder
// and build the model
//

Domain *theDomain = new Domain();

// create the nodes using constructor:
// Node(tag, ndof, crd1, crd2)
// and then add them to the domain

Node *node1 = new Node(1, 2, 0.0, 0.0);
Node *node2 = new Node(2, 2, 144.0, 0.0);
Node *node3 = new Node(3, 2, 168.0, 0.0);
Node *node4 = new Node(4, 2, 72.0, 96.0);
theDomain->addNode(node1);
theDomain->addNode(node2);
theDomain->addNode(node3);
theDomain->addNode(node4);

// create an elastic material using constriuctor:
// ElasticMaterialModel(tag, E)

UniaxialMaterial *theMaterial = new ElasticMaterial(1, 3000);

// create the truss elements using constructor:
// Truss(tag, dim, nd1, nd2, Material &,A)
// and then add them to the domain

Truss *truss1 = new Truss(1, 2, 1, 4, *theMaterial, 10.0);
Truss *truss2 = new Truss(2, 2, 2, 4, *theMaterial, 5.0);
Truss *truss3 = new Truss(3, 2, 3, 4, *theMaterial, 5.0);
theDomain->addElement(truss1);
theDomain->addElement(truss2);
theDomain->addElement(truss3);

// create the single-point constraint objects using constructor:
// SP_Constraint(tag, nodeTag, dofID, value)
// and then add them to the domain

SP_Constraint *sp1 = new SP_Constraint(1, 1, 0, 0.0);
SP_Constraint *sp2 = new SP_Constraint(2, 1, 1, 0.0);
SP_Constraint *sp3 = new SP_Constraint(3, 2, 0, 0.0);
SP_Constraint *sp4 = new SP_Constraint(4, 2, 1, 0.0);
SP_Constraint *sp5 = new SP_Constraint(5, 3, 0, 0.0);
SP_Constraint *sp6 = new SP_Constraint(6, 3, 1, 0.0);
theDomain->addSP_Constraint(sp1);
theDomain->addSP_Constraint(sp2);
theDomain->addSP_Constraint(sp3);
theDomain->addSP_Constraint(sp4);
theDomain->addSP_Constraint(sp5);
theDomain->addSP_Constraint(sp6);

// construct a linear time series object using constructor:
// LinearSeries()

TimeSeries *theSeries = new LinearSeries();

// construct a load pattren using constructor:
// LoadPattern(tag)
// and then set it's TimeSeries and add it to the domain

LoadPattern *theLoadPattern = new LoadPattern(1);
theLoadPattern->setTimeSeries(theSeries);
theDomain->addLoadPattern(theLoadPattern);

// construct a nodal load using constructor:
// NodalLoad(tag, nodeID, Vector &)
// first construct a Vector of size 2 and set the values NOTE C INDEXING
// then construct the load and add it to the domain

Vector theLoadValues(2);
theLoadValues(0) = 100.0;
theLoadValues(1) = -50.0;
NodalLoad *theLoad = new NodalLoad(1, 4, theLoadValues);
theDomain->addNodalLoad(theLoad, 1);

// create an Analysis object to perform a static analysis of the model
// - constructs:
// AnalysisModel of type AnalysisModel,
// EquiSolnAlgo of type Linear
// StaticIntegrator of type LoadControl
// ConstraintHandler of type Penalty
// DOF_Numberer which uses RCM
// LinearSOE of type Band SPD
// and then the StaticAnalysis object

AnalysisModel *theModel = new AnalysisModel();
EquiSolnAlgo *theSolnAlgo = new Linear();
StaticIntegrator *theIntegrator = new LoadControl(1.0, 1, 1.0, 1.0);
ConstraintHandler *theHandler = new PenaltyConstraintHandler(1.0e8,1.0e8);
RCM *theRCM = new RCM();
DOF_Numberer *theNumberer = new DOF_Numberer(*theRCM);
BandSPDLinSolver *theSolver = new BandSPDLinLapackSolver();
LinearSOE *theSOE = new BandSPDLinSOE(*theSolver);

StaticAnalysis theAnalysis(*theDomain,
*theHandler,
*theNumberer,
*theModel,
*theSolnAlgo,
*theSOE,
*theIntegrator);

// perform the analysis & print out the results for the domain
int numSteps = 1;
theAnalysis.analyze(numSteps);
opserr << *theDomain;

exit(0);
}


Since I don't know what and how to add the header files or lib. Of course it fails.

But even I copy all the headerfiles and *.lib,add it in the properties,It still don't works,and the error information as follows:(All error LNK2019)

1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Vector::~Vector(void)" (??1Vector@@QAE@XZ),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall StaticAnalysis::~StaticAnalysis(void)" (??1StaticAnalysis@@UAE@XZ),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "class OPS_Stream & __cdecl operator<<(class OPS_Stream &,class Domain &)" (??6@YAAAVOPS_Stream@@AAV0@AAVDomain@@@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall StaticAnalysis::analyze(int)" (?analyze@StaticAnalysis@@QAEHH@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall StaticAnalysis::StaticAnalysis(class Domain &,class ConstraintHandler &,class DOF_Numberer &,class AnalysisModel &,class EquiSolnAlgo &,class LinearSOE &,class StaticIntegrator &,class ConvergenceTest *)" (??0StaticAnalysis@@QAE@AAVDomain@@AAVConstraintHandler@@AAVDOF_Numberer@@AAVAnalysisModel@@AAVEquiSolnAlgo@@AAVLinearSOE@@AAVStaticIntegrator@@PAVConvergenceTest@@@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall BandSPDLinSOE::BandSPDLinSOE(class BandSPDLinSolver &)" (??0BandSPDLinSOE@@QAE@AAVBandSPDLinSolver@@@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall BandSPDLinLapackSolver::BandSPDLinLapackSolver(void)" (??0BandSPDLinLapackSolver@@QAE@XZ),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall DOF_Numberer::DOF_Numberer(class GraphNumberer &)" (??0DOF_Numberer@@QAE@AAVGraphNumberer@@@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall RCM::RCM(bool)" (??0RCM@@QAE@_N@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall PenaltyConstraintHandler::PenaltyConstraintHandler(double,double)" (??0PenaltyConstraintHandler@@QAE@NN@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall LoadControl::LoadControl(double,int,double,double)" (??0LoadControl@@QAE@NHNN@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Linear::Linear(int)" (??0Linear@@QAE@H@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall AnalysisModel::AnalysisModel(void)" (??0AnalysisModel@@QAE@XZ),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall NodalLoad::NodalLoad(int,int,class Vector const &,bool)" (??0NodalLoad@@QAE@HHABVVector@@_N@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Vector::Vector(int)" (??0Vector@@QAE@H@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall LoadPattern::LoadPattern(int)" (??0LoadPattern@@QAE@H@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall LinearSeries::LinearSeries(int,double)" (??0LinearSeries@@QAE@HN@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall SP_Constraint::SP_Constraint(int,int,double,bool)" (??0SP_Constraint@@QAE@HHN_N@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Truss::Truss(int,int,int,int,class UniaxialMaterial &,double,double,int)" (??0Truss@@QAE@HHHHAAVUniaxialMaterial@@NNH@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall ElasticMaterial::ElasticMaterial(int,double,double)" (??0ElasticMaterial@@QAE@HNN@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Node::Node(int,int,double,double)" (??0Node@@QAE@HHNN@Z),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Domain::Domain(void)" (??0Domain@@QAE@XZ),该符号在函数 _main 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall StandardStream::StandardStream(int)" (??0StandardStream@@QAE@H@Z),该符号在函数 "void __cdecl `dynamic initializer for 'sserr''(void)" (??__Esserr@@YAXXZ) 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall StandardStream::~StandardStream(void)" (??1StandardStream@@UAE@XZ),该符号在函数 "void __cdecl `dynamic atexit destructor for 'sserr''(void)" (??__Fsserr@@YAXXZ) 中被引用


So I wish if someone could tell me how to set the config so that my own C++ file can run.

Thanks so much !

xjtuss
Posts: 1
Joined: Wed Mar 05, 2014 4:17 am
Location: southeast university

Re: Problem in building EXAMPLE

Post by xjtuss » Tue Apr 12, 2016 5:19 am

English, please

Post Reply