如何修复:使用Makefile和G ++对foo()的未定义引用

时间:2019-07-29 09:48:43

标签: c++ linker

我一直试图再次进入C ++,并且在尝试编译时遇到链接器错误:

main.cpp :(。text + 0x92):对`eval(std :: string,double,double,double,double)'的未定义引用

我已经尝试过分别编译每个文件,然后手动链接,但是它永远无法工作。

我尝试了其他类似职位提供的众多解决方案,但这些方法均无济于事,而且我不知道如何解决我的问题(这似乎并不难)

main.cpp:

#include "functions.h" 

double eval(std::string expression_s, double x, double y, double z)
{
        typedef exprtk::symbol_table<double> symbol_table_t;
        typedef exprtk::expression<double>     expression_t;
        typedef exprtk::parser<double>             parser_t;

        symbol_table_t symbol_table0;
        symbol_table_t symbol_table1;
    symbol_table_t symbol_table2;

        expression_t   expression;
        parser_t       parser;

        symbol_table0.add_variable("x",x);
        symbol_table1.add_variable("y",y);
    symbol_table2.add_variable("z",z);

        expression.register_symbol_table(symbol_table0);
        expression.register_symbol_table(symbol_table1);
        expression.register_symbol_table(symbol_table2);

        parser.compile(expression_s,expression);

    std::cout << expression.value();

    return expression.value();

}

functions.cpp:

ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED

#include "exprtk/exprtk.hpp"
#include <iostream>

double eval(std::string expression_s, double x, double y, double z);

#endif

functions.hpp:

CC = g++
EXEC = Crystal_MET
LIBS = 
FLAGS = 

all: main.o
    $(CC) *.o -o $(EXEC) $(LIBS)

main.o : functions.o main.cpp functions.h
    $(CC) main.cpp -c $(FLAGS)

functions.o : functions.cpp functions.h
    $(CC) functions.cpp -c $(FLAGS)

clear :
    rm -f *.o

mr_proper :
    rm -f *.o $(EXEC)

Makefile:

<template>
  <!-- Image modal -->
  <div
    class="modal fade"
    id="gallery-multi"
    tabindex="-1"
    role="dialog"
    aria-labelledby="galleryLabel"
    aria-hidden="true"
  >
    <div class="modal-dialog modal-dialog-centered modal-lg " role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="gallery">Gallery</h5>
          <button type="button" class="close" @click="closeModal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <vue-select-image
            :dataImages="dataImages"
            :is-multiple="true"
            @onselectmultipleimage="onSelectMultipleImage"
            :h="'90'"
            :w="'140'"
          ></vue-select-image>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" @click="closeModal()">Close</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import VueSelectImage from "vue-select-image";
import "vue-select-image/dist/vue-select-image.css";
export default {
  name: "selectMultiImg",
  data() {
    return {
      multiID:[],
      dataImages: [
        {
          id: "",
          src: "",
          alt: ""
        }
      ]
    };
  },
  methods: {
    closeModal() {
      $("#gallery-multi").modal("hide");
    },
    onSelectMultipleImage: function(data) {
      
      this.multiID = data.id;
      this.$emit('multiImg', this.multiID);
    }
  },
  components: { VueSelectImage },
  mounted() {
    axios.get("/api/gallery").then(response => {
      this.dataImages = response.data.map((obj, index) => {
        return {
          id: obj.id,
          src: obj.thumb,
          alt: obj.name
        };
      });
    });
  }
};
</script>

1 个答案:

答案 0 :(得分:1)

由于以下原因,

main.cpp是针对与functions.cpp不同的ABI进行编译的:

#define _GLIBCXX_USE_CXX11_ABI 0

从main.cpp中删除该行,或将其添加到functions.cpp中。

更多详细信息:https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html