UrticaDioica UrticaDioica - 1 month ago 10
C++ Question

Visual C++ - header of my static library not found

I'm trying to make my own static library, but I can't use it in my another project. I compiled the library in command prompt with this command:

cl /c /EHsc Matrix3.cpp


I added it as a reference to my project, and I added the directory containing the compiled .lib file to my project.

The library code is below.

Header file:

#pragma once

typedef struct
{
float m[3][3];
} matrix3;

class Matrix3
{
public:
Matrix3();
~Matrix3();
matrix3* MatrixAdd(matrix3* A, matrix3* B);
matrix3* ScalarMatrixMul(float scalar, matrix3* A);
matrix3* MatrixMult(matrix3* A, matrix3* B);
};


.cpp file:

#include "Matrix3.h"

Matrix3::Matrix3() {
}


Matrix3::~Matrix3() {
}

matrix3* Matrix3::MatrixAdd(matrix3* A, matrix3* B) {

matrix3* result = new matrix3;

for (int row = 0; row < 3; row++)
for (int col = 0; col < 3; col++)
result->m[row][col] = A->m[row][col] + B->m[row][col];

return result;
}

matrix3* Matrix3::ScalarMatrixMul(float scalar, matrix3* A) {

matrix3* result = new matrix3;

for (int row = 0; row < 3; row++)
for (int col = 0; col < 3; col++)
result->m[row][col] = scalar * A->m[row][col];

return result;
}

matrix3* Matrix3::MatrixMult(matrix3* A, matrix3* B) {

matrix3* result = new matrix3;

float sum;

for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
sum = 0;
for (int k = 0; k < 3; k++)
sum += A->m[row][k] * B->m[k][col];
result->m[row][col] = sum;
}
}

return result;
}

Answer

In your other project settings, in C/C++->General->Additional Include Directories you need to specify directory where Matrix3.h is placed. Otherwise compiler will search in the same directory where the source file being compiled is placed.