包含本元库时的汇编错误

发布于 2025-02-06 12:02:33 字数 3139 浏览 1 评论 0原文

我目前正在使用eigen库,这是我唯一包含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();
};

我使用makefile进行编译:(

我是新手makefile,所以如果我可以改进,请告诉我) (eigen安装在工作目录中/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/*

但是,当我制作时,终端似乎会输出一些库本身的错误(???,

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'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 
lt; -o $@

FM.o: src/FM_alg.cpp src/FM_alg.h
    $(CC) $(CFLAGS) $(OPTFLAGS) 
lt; -o $@
partition.o: src/partition.cpp src/partition.h
    $(CC) $(CFLAGS) $(OPTFLAGS) 
lt; -o $@
Kraftwerk2.o: src/Kraftwerk2.cpp src/Kraftwerk2.h
    $(CC) ./eigen $(CFLAGS) $(OPTFLAGS) 
lt; -o $@
module.o: src/module.cpp src/module.h
    $(CC) $(CFLAGS) $(OPTFLAGS) 
lt; -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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文