1

I am new to C++. I am trying to modify a very complex video codec code as part of my final year school project. I have already asked it on another thread but got no help. This is my code:

This is the header file in which I have declared three extern variables:

yuv.h

#include <vector>
namespace X265_NS 
{
extern int frameNumber;
extern int frameSize;
extern std::vector<int>numbers;

class YUVInput : public InputFile, public Thread
{
protected:

// some more variables

public:

// more variables and function declarations

};
}

This is the first file that uses these extern variables:

yuv.cpp

#include "yuv.h"
//more includes
#include <vector>

namespace X265_NS {
    int frameNumber;
    int frameSize;
    std::vector<int>numbers;
}

using namespace X265_NS;  

// some stuff and function calls
// here I use my extern variables in a function

frameNumber = readCount.get();
frameSize = ceil((double)height / 32) * ceil((double)width / 32);

//more stuff

bool YUVInput::populateFrameQueue()
{
   if(read<1)
             {
                  ifstream file("/home/abu-bakr/bin/test.txt");
                  int number;
                  while (file >> number)
                           numbers.push_back(number);
             }
}

// more stuff

This is the second class where I am using these extern variables:

analysis.cpp

#include "yuv.h"
#include <vector>
....
using namespace X265_NS;

// some stuff

// its in a function and only place where I am using these variables
int qp_ctu = numbers.at((ctu.m_cuAddr + 1) + (frameSize*(frameNumber - 1)));

// more stuff

This is the error I am getting that is making me really confused:

analysis.cpp
1>C:\x265_2.2\x265_2.2\source\encoder\analysis.cpp(170): warning C4244: '=' : conversion from 'int' to 'int8_t', possible loss of data
1>C:\x265_2.2\x265_2.2\source\encoder\analysis.cpp(2814): error C2065: 'numbers' : undeclared identifier
1>C:\x265_2.2\x265_2.2\source\encoder\analysis.cpp(2814): error C2228: left of '.at' must have class/struct/union
1>          type is ''unknown-type''
1>C:\x265_2.2\x265_2.2\source\encoder\analysis.cpp(2814): error C2065: 'frameSize' : undeclared identifier
1>C:\x265_2.2\x265_2.2\source\encoder\analysis.cpp(2814): error C2065: 'frameNumber' : undeclared identifier

yuv.cpp
2>C:\x265_2.2\x265_2.2\source\input\yuv.cpp(219): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
2>x265-static.lib(analysis.obj) : error LNK2005: "int x265::frameNumber" (?frameNumber@x265@@3HA) already defined in yuv.cpp.obj
2>x265-static.lib(analysis.obj) : error LNK2005: "int x265::frameSize" (?frameSize@x265@@3HA) already defined in yuv.cpp.obj
2>     Creating library C:/x265_2.2/x265_2.2/build/vc10-x86/Debug/x265.lib and object C:/x265_2.2/x265_2.2/build/vc10-x86/Debug/x265.exp
2>C:\x265_2.2\x265_2.2\build\vc10-x86\Debug\x265.exe : fatal error LNK1169: one or more multiply defined symbols found
4
  • The namespace in the source code X265_NS is different from the one in the error messages, x265. Is there a macro here? Is that macro defined the same everywhere? Commented Mar 29, 2017 at 21:52
  • There are no macros used. Infact when I hover my mouse on frameNumber in yuv.h file, tool tip that appears show "int x265::frameNumber" same that appears in error, although the name space mentioned is X265_NS. Plus there is another comment mention in the code is "// private x265 namespace" under the opening bracket of X265_NS. Commented Mar 29, 2017 at 22:16
  • Part of your problem is that you're compiling the source code, and then linking to a library that already contains the same source code. However I'm confused why the build process even ran the linker when there was a compile error. Commented Mar 29, 2017 at 22:51
  • 1
    If you're basing this off the git project github.com/videolan/x265, the macro define of X265_NS to x256 is happening inside the source/CMakeLists.txt file on line 385: add_definitions(-DX265_NS=${X265_NS}). It looks like you're using Windows so maybe it's some other build file. Regardless, it's clear that's not actually the namespace and the code expects the build system to define it on the compiler command line. Commented Mar 30, 2017 at 1:45

2 Answers 2

5

You might be including a wrong file. Most likely there's another yuv.h file in some library source code which gets included in analysis.cpp instead of the one you need. You can quickly check this by adding some erroneous code into your yuv.h and trying to compile analysis.cpp.

Sign up to request clarification or add additional context in comments.

1 Comment

I just did not notice it but you were right, it was including another yuv.h file.
0

Check analysis.cpp to see if you DON'T define

namespace X265_NS {
    int frameNumber;
    int frameSize;
    std::vector<int>numbers;
}

again.

or

Maybe you have a wrong initialization like:

int frameSize = 0;

instead of:

frameSize = 0;

1 Comment

Both things are written as required :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.