I have only 2 files in my folder - Gnuplot_example.cpp and Makefile.
Gnuplot_example.cpp
#include "Snap.h"
int main(int argc, char* argv[]) {
TIntH expCount, PoissonCount;
TRnd a;
double binSize=0.1;
//exponential distribution
for (int i=0; i<10000; ++i)
{
double num=a.GetExpDev(1);
expCount.AddDat((int)(num/binSize))++;
}
//Poisson distribution
for (int i=0; i<10000; ++i)
{
double num=a.GetPoissonDev(10);
PoissonCount.AddDat((int)(num/binSize))++;
}
expCount.Sort(true,true);
PoissonCount.Sort(true,true);
{
TVec<TPair<TFlt, TFlt > > XY1, XY2;
for (int i=0; i<expCount.Len(); ++i)
XY1.Add(TFltPr(expCount.GetKey(i)*binSize, expCount[i]+0.0));
for (int i=0; i<PoissonCount.Len(); ++i)
XY2.Add(TFltPr(PoissonCount.GetKey(i)*binSize,PoissonCount[i]+0.0));
TGnuPlot Gp("distribution", "Exponential and Poisson Distribution");
Gp.AddPlot(XY1, gpwLinesPoints, "Exponential");
Gp.AddPlot(XY2, gpwLinesPoints, "Poisson");
Gp.SetXYLabel("value", "count");
Gp.SavePng(); //or Gp.SaveEps();
}
return 0;
}
Makefile
#
# Makefile for non-Microsoft compilers
#
all: $(Gnuplot_example)
# COMPILE
$(Gnuplot_example): $(Gnuplot_example).cpp $(DEPH) $(DEPCPP) $(EXSNAP)/Snap.o
$(CC) $(CXXFLAGS) -o $(Gnuplot_example) $(Gnuplot_example).cpp $(DEPCPP) $(EXSNAP)/Snap.o -I$(EXSNAP) -I$(EXSNAPADV) -I$(EXGLIB) -I$(EXSNAPEXP) $(LDFLAGS) $(LIBS)
$(EXSNAP)/Snap.o:
make -C $(EXSNAP)
clean:
rm -f *.o $(Gnuplot_example) $(Gnuplot_example).exe
rm -rf Debug Release
When I am using command 'make' in this folder, it says:
make: Nothing to be done for 'all'.
and there is no object file created. I have gone through other answers and I made sure to use tab in rules instead of spaces. I am new to this. I am not getting what is wrong.
Thanks for any Help!!
Related
I'm currently using eigen library, and this is the only file that I include eigen:
Kraftwerk2.cpp:
#include "Kraftwerk2.h"
Kraftwerk2::Kraftwerk2(int n){ //n: num instances
Connectivity_mat.resize(n,n);
}
int Kraftwerk2::Parse_Inst_Name(string s){ //input: String("M12"), output: int 12
return stoi(s.substr(1));
}
void Kraftwerk2::Generate_Connectivity_matrix(unordered_map<string, net> map){
for(auto& it : map){
int n =it.second.net_pin.size();
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
Connectivity_mat(i,j) = Connectivity_mat(i,j) +1;
}
}
}
}
void Kraftwerk2::Print_Mat(){
IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
cout << Connectivity_mat.format(CleanFmt);
}
Kraftwerk2.h:
#include <iostream>
#include <Eigen/Core>
#include "module.h"
using namespace std;
// unordered_map<string, instance> instances;
// unordered_map<string, net> nets;
using namespace Eigen;
class Kraftwerk2{
public:
Kraftwerk2(int);
MatrixXd Connectivity_mat;
int Parse_Inst_Name(string);
void Generate_Connectivity_matrix(unordered_map<string, net>);
void Print_Mat();
};
And I use makefile for compiling:
(I'm pretty new to makefile, so if there's something I can improve, please tell me)
(Eigen is installed in the working directory ./eigen)
# CC and CFLAGS are varilables
CC = g++
CFLAGS = -c
OPTFLAGS = -O2
DBGFLAGS = -g -D_DEBUG_ON_
# make all
all : bin/partition
#echo -n "make complete!"
# optimized version
bin/partition: main_opt.o FM.o partition.o module.o Kraftwerk2.o
$(CC) $(OPTFLAGS) main_opt.o FM.o partition.o module.o Kraftwerk2.o -o bin/partition
main_opt.o: src/main.cpp src/FM_alg.h src/partition.h src/module.h src/Kraftwerk2.h
$(CC) -I ./eigen $< -o $#
FM.o: src/FM_alg.cpp src/FM_alg.h
$(CC) $(CFLAGS) $(OPTFLAGS) $< -o $#
partition.o: src/partition.cpp src/partition.h
$(CC) $(CFLAGS) $(OPTFLAGS) $< -o $#
Kraftwerk2.o: src/Kraftwerk2.cpp src/Kraftwerk2.h
$(CC) ./eigen $(CFLAGS) $(OPTFLAGS) $< -o $#
module.o: src/module.cpp src/module.h
$(CC) $(CFLAGS) $(OPTFLAGS) $< -o $#
# clean all the .o and executable files
clean:
rm -rf *.o lib/*.a lib/*.o bin/*
However, when I make, the terminal seems to output some error that comes form the library itself(???
g++ -I ./eigen src/main.cpp -o main_opt.o
In file included from ./eigen/Eigen/Core:269,
from src/Kraftwerk2.h:2,
from src/main.cpp:4:
./eigen/Eigen/src/Core/util/IndexedViewHelper.h:69:23: error: declaration of ‘template<class first> constexpr Eigen::Index Eigen::internal::first(const first&)’ shadows template parameter
69 | EIGEN_CONSTEXPR Index first(const T& x) EIGEN_NOEXCEPT { return x.first(); }
| ^~~~~
./eigen/Eigen/src/Core/util/IndexedViewHelper.h:68:10: note: template parameter ‘first’ declared here
68 | template<typename T>
| ^~~~~~~~
make: *** [makefile:15: main_opt.o] Error 1
I would be so appreciated if anybody can tell me what's wrong with this.
so after building and installing the MATIO library using CMake, I am now having problems compiling it. Here's my code:
#include <iostream>
#include <matio.h>
#define tS(x) std::cout<<"\t"<<(#x)<<" == "<<(x)<<"\n"
int main(int argc, char **argv)
{
const char *fileName = argc==1?"./S.mat":argv[1] ;
mat_t *mat = Mat_Open(fileName,MAT_ACC_RDONLY);
if(mat)
{
std::cout<<"A file was opened for reading\n\tmat == "<<mat<<"\n" ;
matvar_t *matVar=0 ;
std::cout<<"Writing out the data\n\n" ;
std::cout<<"x:\n" ;
matVar = Mat_VarRead(mat, (char*)"x") ;
if(matVar)
{
int xSize = matVar->nbytes/matVar->data_size ;
const double *xData = static_cast<const double*>(matVar->data) ;
for(int i=0; i<xSize; ++i)
{
std::cout<<"\tx["<<i<<"] = "<<xData[i]<<"\n" ;
}
std::cout<<"\n" ;
for(int i=0; i<matVar->rank; ++i)
{
std::cout<<"\tdim["<<i<<"] == "<<matVar->dims[i]<<"\n" ;
}
}
std::cout<<"y:\n" ;
matVar = Mat_VarRead(mat, (char*)"y") ;
int ySize = matVar->nbytes/matVar->data_size ;
const double *yData = static_cast<const double*>(matVar->data) ;
for(int i=0; i<ySize; ++i)
{
double d = yData[i] ;
std::cout<<"\ty["<<i<<"] = "<<d<<"\n" ;
}
std::cout<<"\n" ;
for(int i=0; i<matVar->rank; ++i)
{
std::cout<<"\tdim["<<i<<"] == "<<matVar->dims[i]<<"\n" ;
}
Mat_Close(mat);
}
else
{
std::cout<<"File cannot be opened\n" ;
return 1;
}
return 0;
}
However I get the following error:
C:\WINDOWS\system32\cmd.exe /C ""C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" -j4 SHELL=cmd.exe -e -f Makefile"
"----------Building project:[ Test - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe" -c "C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp" -std=c++14 -Wall -g -O0 -Wall -I/Users/RS3/matio/getopt -I/matio/include -L/matio/bin -lmatio -o ./Debug/main.cpp.o -I. -I. -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\Halton" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\quasimvnrnd"
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe" -o ./Debug/Test #"Test.txt" -L. -L"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9" -static-libgcc -static-libstdc++
./Debug/main.cpp.o: In function `main':
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:38: undefined reference to `Mat_Open'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:46: undefined reference to `Mat_VarRead'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:63: undefined reference to `Mat_VarRead'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:77: undefined reference to `Mat_Close'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Test.mk:81: Debug/Test] Error 1
mingw32-make.exe[1]: Leaving directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
mingw32-make.exe: *** [Makefile:5: All] Error 2
====4 errors, 0 warnings====
I looked for this error right and left and I know the linker can't find the library for some reason despite me having the following compiler options:
-g;-O0;-Wall;-I/Users/RS3/matio/getopt;-I/matio/include;-L/matio/bin;-lmatio
I'm using Codelite IDE.
I am not sure what I am missing and it's driving me crazy. Any help would be appreciated!
Hello I am seeing some errors in my attempts to make a basic SystemC project. It looks like a slight mismatch of types, but I am not familiar enough with the types from the SystemC library to really know what the issue is. I have more or less taken the code directly from this tutorial.
https://www.youtube.com/watch?v=DSg4PMoUCX4
Currently, my Makefile looks like this
CXX=g++
OBJ= main.o fir_filter.o test_bench.o
INC=- -I /home/epi/jfrye_xilinx/SystemC/systemc-2.3.2/include -I /home/epi/jfrye_xilinx/SystemC/lib/fir_filter/src
LFLAGS=-L/home/epi/jfrye_xilinx/SystemC/systemc-2.3.2/lib-linux64
LIBS=-lsystemc
EXEC=test_fir
all: $(OBJ)
$(CXX) $(OBJS) -o $(EXEC)
main.o: main.cpp
$(CXX) $(INC) $(LFLAGS) $(LIBS) main.cpp
fir_filter.o: fir_filter.cpp fir_filter.h
$(CXX) $(INC) $(LFLAGS) $(LIBS) fir_filter.cpp
test_bench.o: test_bench.cpp test_bench.h
$(CXX) $(INC) $(LFLAGS) $(LIBS) test_bench.cpp
I am seeing these errors when I run make
main.cpp:28:19: error: no match for call to
(sc_core::sc_in<sc_dt::sc_uint<16> >)
(sc_core::sc_signal<sc_dt::sc_int<16> >&)
fir->inp(inp_sig);
main.cpp:29:21: error: no match for call to
(sc_core::sc_out<sc_dt::sc_uint<16> >)
(sc_core::sc_signal<sc_dt::sc_int<16> >&)
fir->outp(outp_sig);
Here is main.cpp
#include <systemc.h>
#include "fir_filter.h"
#include "test_bench.h"
SC_MODULE(SYSTEM)
{
test_bench *tb;
fir_filter *fir;
sc_signal<bool> rst_sig;
sc_signal< sc_int<16> > inp_sig;
sc_signal< sc_int<16> > outp_sig;
sc_clock clk_sig;
SC_CTOR(SYSTEM)
: clk_sig("clk_sig", 10, SC_NS)
{
tb = new test_bench("tb");
tb->clk(clk_sig);
tb->rst(rst_sig);
tb->inp(inp_sig);
tb->outp(outp_sig);
fir = new fir_filter("fir");
fir->clk(clk_sig);
fir->rst(rst_sig);
fir->inp(inp_sig);
fir->outp(outp_sig);
}
~SYSTEM()
{
delete tb;
delete fir;
}
};
SYSTEM *top = NULL;
int sc_main(int argc, char *argv[])
{
top = new SYSTEM("top");
sc_start();
return 0;
}
And lastly, fir_filter.h
#include <systemc.h>
SC_MODULE( fir_filter )
{
sc_in<bool> clk;
sc_in<bool> rst;
sc_in< sc_uint<16> > inp;
sc_out< sc_uint<16> > outp;
void fir_main();
SC_CTOR( fir_filter )
{
SC_CTHREAD( fir_main, clk.pos());
reset_signal_is( rst, true);
}
};
Update:
Thanks to the answers provided, I was able to change the two modules to ensure that the types were matching, whether signed or unsigned.
However make is still giving me this error. I did not include it originally because I did not realize it would break compilation.
g++: error: -E or -x required when input is from standard input make:
*** [main.o] Error 1
In your SYSTEM module, it shouldn't be :
sc_signal< sc_int<16> > inp_sig;
sc_signal< sc_int<16> > outp_sig;
but instead :
sc_signal< sc_uint<16> > inp_sig;
sc_signal< sc_uint<16> > outp_sig;
as inp in the FIR Filter module is a sc_in< sc_uint<16> >.
Alright, new user here, and I've got a problem. I'm a new c++ student, and I have no prior experience in this language (before about 3 months ago). My assignment is as follows:
Write a program that declares an array darray of 50 elements of type double. Initialize the array so that the first 25 elements are equal to the square of the index variable, and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.
The program should have two functions: a function, initArray(), which initializes the array elements, and a function, prArray(), which prints the elements.
I have that, it's as follows
#include "printArray.h"
#include "initializearray.h"
#include "Main.h"
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
double initArray();
double prArray(double arrayone[50]);
double * dArray;
int main() {
dArray[50] = initArray();
system("PAUSE");
prArray(dArray);
system("PAUSE");
return 0;
}
#include "printArray.h"
#include "initializearray.h"
#include "Main.h"
#include <iostream>
#include <string>
using namespace std;
double prArray(double arraytwo[50])
{
for (int x = 0; x < 50; x++) {
cout << arraytwo[x];
if (x = 9 || 19 || 29 || 39 || 49) {
cout << endl;
}
}
return 0;
}
#include "printArray.h"
#include "initializearray.h"
#include "Main.h"
#include <iostream>
#include <string>
int x = 0;
double arrayone[50];
double initArray()
{
for (x = 0; x < 25; x++) {
arrayone[x] = (x*x);
}
for (x = 25; x <= 50; x++) {
arrayone[x] = (x * 3);
}
return arrayone[50];
}
Now my problem is that the assignment goes on to say
Write a Makefile to compile the program above that minimizes recompiling items upon changes. (e.g., if one function file gets updated, only the necessary file(s) are recompiled.) Include a clean target that removes compiled objects if invoked.
I have a basic makefile:
CC=g++
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=Main.cpp initializeArray.cpp printArray.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=Main
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $#
.cpp.o:
$(CC) $(CFLAGS) $< -o $#
Now, what I need help with is turning this into a makefile that satisfies the assignment conditions - preferably with step-by-step instructions so that I can learn from this.
Modified your Makefile to:
Automatically generate header dependencies.
Re-build and re-link when Makefile changes.
CXX := g++
LD := ${CXX}
CXXFLAGS := -Wall -Wextra -std=gnu++14 -pthread
LDFLAGS := -pthread
exes :=
# Specify EXEs here begin.
Main.SOURCES := Main.cpp initializeArray.cpp printArray.cpp
exes += Main
# Specify EXEs here end.
all: $(exes)
.SECONDEXPANSION:
get_objects = $(patsubst %.cpp,%.o,${${1}.SOURCES})
get_deps = $(patsubst %.cpp,%.d,${${1}.SOURCES})
# Links executables.
${exes} : % : $$(call get_objects,$$*) Makefile
${LD} -o $# $(filter-out Makefile,$^) ${LDFLAGS}
# Compiles C++ and generates dependencies.
%.o : %.cpp Makefile
${CXX} -o $# -c ${CPPFLAGS} ${CXXFLAGS} -MP -MD $<
# Include the dependencies generated on a previous build.
-include $(foreach exe,${exes},$(call get_deps,${exe}))
.PHONY: all
I want to wrap my C++ OpenCV code with boost::python, and to learn how to do it, I tried a toy example, in which
I use the Boost.Numpy project to provide me with boost::numpy::ndarray.
The C++ function to be wrapped, square() takes a boost::numpy::ndarray and modifies it in place by squaring each element in it.
The exported Python module name is called test.
The square() C++ function is exported as the square name in the exported module.
I am not using bjam because IMO it is too complicated and just doesn't work for me no matter what. I'm using good old make.
Now, here's the code:
// test.cpp
#include <boost/python.hpp>
#include <boost/numpy.hpp>
#include <boost/scoped_array.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
namespace py = boost::python;
namespace np = boost::numpy;
void square(np::ndarray& array)
{
if (array.get_dtype() != np::dtype::get_builtin<int>())
{
PyErr_SetString(PyExc_TypeError, "Incorrect array data type.");
py::throw_error_already_set();
}
size_t rows = array.shape(0), cols = array.shape(1);
size_t stride_row = array.strides(0) / sizeof(int),
stride_col = array.strides(1) / sizeof(int);
cv::Mat mat(rows, cols, CV_32S);
int *row_iter = reinterpret_cast<int*>(array.get_data());
for (int i = 0; i < rows; i++, row_iter += stride_row)
{
int *col_iter = row_iter;
int *mat_row = (int*)mat.ptr(i);
for (int j = 0; j < cols; j++, col_iter += stride_col)
{
*(mat_row + j) = (*col_iter) * (*col_iter);
}
}
for (int i = 0; i < rows; i++, row_iter += stride_row)
{
int *col_iter = row_iter;
int *mat_row = (int*)mat.ptr(i);
for (int j = 0; j < cols; j++, col_iter += stride_col)
{
*col_iter = *(mat_row + j);
}
}
}
BOOST_PYTHON_MODULE(test)
{
using namespace boost::python;
def("square", square);
}
And here's the Makefile:
PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
BOOST_INC = /usr/local/include
BOOST_LIB = /usr/local/lib
OPENCV_LIB = $$(pkg-config --libs opencv)
OPENCV_INC = $$(pkg-config --cflags opencv)
TARGET = test
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic \
$(TARGET).o -L$(BOOST_LIB) -lboost_python \
$(OPENCV_LIB) \
-L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) \
-o $(TARGET).so
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON_INCLUDE) $(OPENCV_INC) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp
With this scheme, I can type make and test.so gets created. But when I try to import it,
In [1]: import test
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-73ae3ffe1045> in <module>()
----> 1 import test
ImportError: ./test.so: undefined symbol: _ZN5boost6python9converter21object_manager_traitsINS_5numpy7ndarrayEE10get_pytypeEv
In [2]:
This is a linker error which I can't seem to fix. Can anyone please help me with what's going on? Do you have (links to) code that already does integrate OpenCV, numpy and Boost.Python without things like Py++ or the likes?.
Okay I fixed this. It was a simple issue, but a sleepy brain and servings of bjam had made me ignore it. In the Makefile, I'd forgotten to put -lboost_numpy that links the Boost.Numpy libs to my lib. So, the modified Makefile looks like this:
PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
BOOST_INC = /usr/local/include
BOOST_LIB = /usr/local/lib
OPENCV_LIB = $$(pkg-config --libs opencv)
OPENCV_INC = $$(pkg-config --cflags opencv)
TARGET = test
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic \
$(TARGET).o -L$(BOOST_LIB) -lboost_python -lboost_numpy \
$(OPENCV_LIB) \
-L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) \
-o $(TARGET).so
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON_INCLUDE) $(OPENCV_INC) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp