海鹦 2021-05-05 17:32 采纳率: 100%
浏览 106
已采纳

VS2019的c++代码,外部依赖项中有stasm_lib.h文件,但在引用时报错

报错:error LNK2019: 无法解析的外部符号 stasm_init,函数 wmain 中引用了该符号

 

stasm_lib.h代码

#ifndef STASM_LIB_H
#define STASM_LIB_H

static const int stasm_NLANDMARKS = 77; // number of landmarks

extern const char* const stasm_VERSION;

extern "C"
int stasm_init(              // call once, at bootup
    const char*  datadir,    // in: directory of face detector files
    int          trace);     // in: 0 normal use, 1 trace to stdout and stasm.log

extern "C"
int stasm_open_image(        // call once per image, detect faces
    const char*  img,        // in: gray image data, top left corner at 0,0
    int          width,      // in: image width
    int          height,     // in: image height
    const char*  imgpath,    // in: image path, used only for err msgs and debug
    int          multiface,  // in: 0=return only one face, 1=allow multiple faces
    int          minwidth);  // in: min face width as percentage of img width

extern "C"
int stasm_search_auto(       // call repeatedly to find all faces
    int*         foundface,  // out: 0=no more faces, 1=found face
    float*       landmarks); // out: x0, y0, x1, y1, ..., caller must allocate

extern "C"
int stasm_search_single(     // wrapper for stasm_search_auto and friends
    int*         foundface,  // out: 0=no face, 1=found face
    float*       landmarks,  // out: x0, y0, x1, y1, ..., caller must allocate
    const char*  img,        // in: gray image data, top left corner at 0,0
    int          width,      // in: image width
    int          height,     // in: image height
    const char*  imgpath,    // in: image path, used only for err msgs and debug
    const char*  datadir);   // in: directory of face detector files

extern "C"                   // find landmarks, no OpenCV face detect
int stasm_search_pinned(     // call after the user has pinned some points
    float*       landmarks,  // out: x0, y0, x1, y1, ..., caller must allocate
    const float* pinned,     // in: pinned landmarks (0,0 points not pinned)
    const char*  img,        // in: gray image data, top left corner at 0,0
    int          width,      // in: image width
    int          height,     // in: image height
    const char*  imgpath);   // in: image path, used only for err msgs and debug

extern "C"
const char* stasm_lasterr(void); // return string describing last error

extern "C"
void stasm_force_points_into_image( // force landmarks into image boundary
    float*       landmarks,         // io
    int          ncols,             // in
    int          nrows);            // in

extern "C"
void stasm_convert_shape( // convert stasm_NLANDMARKS points to given number of points
    float* landmarks,     // io: return all points zero if can't do conversion
    int    nlandmarks);   // in: see ConvertShape

// stasm_printf is like printf but also prints to the file stasm.log if it
// is open.  The file stasm.log will be open if stasm_init was called with
// trace=1.  This function was added primarily for the programs that test
// the stasm library.

extern "C"
void stasm_printf(const char* format, ...); // print to stdout and stasm.log

#endif // STASM_LIB_H

 

源代码:

#include <iostream>

#include <tchar.h>
#include <opencv2/opencv.hpp>
#include <stasm_lib.h>
#include <stasm_lib_ext.h>  // needed for stasm_search_auto_ext
#include <stasm_landmarks.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    //1.读取图片
    const char* path = "F://1.jpg";
    const cv::Mat_<unsigned char> img(cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE));
    cv::Mat Src = cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE);
    //2.防止图片是空的
    if (img.empty())
    {
        printf("Cannot load %s\n", path);
        system("pause");
        return 0;
    }
    //3.初始化stasm
    const int trace = 0;//想跟踪日志,设置为1
    if(!stasm_init("../data", trace))
    {
        printf("stasm_init failed: %s\n", stasm_lasterr());
        system("pause");
        return 0;
    }
    //4.设置相关参数
    const int multi = 0;//设置是否检测多个人脸,只检测1个设置为0
    const int minwidth = 25;//最小人脸尺寸(猜测是正方形)
    //加载图片
    if (!stasm_open_image((const char*)img.data, img.cols, img.rows, path, multi, minwidth))
    {
        printf("stasm_open_image failed: %s\n", stasm_lasterr());
        system("pause");
        return 0;
    }
    //设置特征点
    float landmarks[2 * stasm_NLANDMARKS];
    int foundface = 0;
    float estyaw;
    //判断运行情况
    if (!stasm_search_auto_ext(&foundface, landmarks, &estyaw))
    {
        printf("stasm_search_auto failed: %s\n", stasm_lasterr());
    }
    //找到人脸
    if (foundface)
    {
        for (int i = 0; i < stasm_NLANDMARKS; i++)
        {
            const int ix = cvRound(landmarks[i * 2]);       // this point
            const int iy = cvRound(landmarks[i * 2 + 1]);
            cv::circle(Src, cv::Point(ix, iy), 1, cv::Scalar(255, 0, 0), -1);
        }

    }
    cv::imshow("test", Src);
    cv::waitKey(0);
    return 0;
}

 

 

报错:

1>ConsoleApplication2.obj : error LNK2019: 无法解析的外部符号 stasm_init,函数 wmain 中引用了该符号
1>ConsoleApplication2.obj : error LNK2019: 无法解析的外部符号 stasm_open_image,函数 wmain 中引用了该符号
1>ConsoleApplication2.obj : error LNK2019: 无法解析的外部符号 stasm_lasterr,函数 wmain 中引用了该符号
1>ConsoleApplication2.obj : error LNK2019: 无法解析的外部符号 stasm_search_auto_ext,函数 wmain 中引用了该符号
1>H:\opencv2410\opencv\build\x64\vc10\...\..\include\ConsoleApplication2.exe : fatal error LNK1120: 4 个无法解析的外部命令

  • 写回答

6条回答 默认 最新

  • 关注

    包含了stasm_lib.h头文件,对应的dll有没有拷贝过来呢?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上