Hi, first time poster here and I am trying to run the Twofish implementation that I found online. I have a very basic knowledge of C++ and I am only trying to get these files to run so that I can analyze encryption times and decryption times for a class project.

I am getting linking errors from twofish.h shown below:


/** \file

#include "cryptlib.h"
#include "misc.h"


/// base class, do not use directly
class Twofish : public FixedBlockSize<16>, public VariableKeyLength<16, 0, 32>
	Twofish(const byte *userKey, unsigned int keylength);
	static word32 h0(word32 x, const word32 *key, unsigned int kLen);
	static word32 h(word32 x, const word32 *key, unsigned int kLen);

	static const byte q[2][256];
	static const word32 mds[4][256];

	SecBlock<word32> m_k;
	SecBlock<word32[256]> m_s;

/// <a href="http://www.weidai.com/scan-mirror/cs.html#Twofish">Twofish</a>
class TwofishEncryption : public Twofish
	TwofishEncryption(const byte *userKey, unsigned int keylength=DEFAULT_KEYLENGTH)
		: Twofish(userKey, keylength) {}

	void ProcessBlock(const byte *inBlock, byte * outBlock) const;
	void ProcessBlock(byte * inoutBlock) const
		{TwofishEncryption::ProcessBlock(inoutBlock, inoutBlock);}

/// <a href="http://www.weidai.com/scan-mirror/cs.html#Twofish">Twofish</a>
class TwofishDecryption : public Twofish
	TwofishDecryption(const byte *userKey, unsigned int keylength=DEFAULT_KEYLENGTH)
		: Twofish(userKey, keylength) {}

	void ProcessBlock(const byte *inBlock, byte * outBlock) const;
	void ProcessBlock(byte * inoutBlock) const
		{TwofishDecryption::ProcessBlock(inoutBlock, inoutBlock);}



The specific errors I am getting are:
Twofish error LNK2001: unresolved external symbol "protected: static unsigned long const (* CryptoPP::Twofish::mds)[256]" (?mds@Twofish@CryptoPP@@1QAY0BAA@$$CBKA)
Twofish error LNK2001: unresolved external symbol "protected: static unsigned char const (* CryptoPP::Twofish::q)[256]" (?q@Twofish@CryptoPP@@1QAY0BAA@$$CBEA)
Twofish error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup

I know that the first two errors mean that I am declaring something and I am not giving the compiler/linker the correct information to understand what is happening. Unfortunately I am not very experienced in coding and do not know much about Visual Studio and how to actually fix these errors.

The last error from what I understand has something to do with Win32 console projects and the way the linker sees characters or something. I have seen people say try changing the character set in the project properties, but that has not worked. If anyone could help me I would greatly appreciate it. If any further information is required just ask I can provide other pieces of code, but figured I would keep that part short for now until I had some guidance.


10 Years
Discussion Span
Last Post by mitrmkar

This looks like it requires some library files that you didn't add. Go to the project settings, go to Configuration Properties->Linker->Input->Additional Dependencies. Add any .lib files you find with the other twofish files in this field. You may have to add the folder they're in to Configuration Properties->Linker->General->Additional Library Dependencies. Also, I'm not sure of your file organization or if you have any other files, but I don't see a main() function anywhere. That could cause your last error.


The code was only from twofish.h there is other code that goes with it, but it also has a few other header files that it calls. I am not so sure about the libraries and I will have to research them a little bit further when I work on it tomorrow. Thanks for the quick reply. Will post updates soon.


When you downloaded the header files, they most likely came with some library files, judging by those errors. You just have to let visual studio know about those files via the method I mentioned before. It probably wouldn't matter too much if you added library files that weren't necessary, so don't hesitate to just add them all (all that came with the headers).


I downloaded the .h and .cpp files from koders.com website and there is a huge list of files on the left, unfortunately I don't see any .lib files. Is there another file extension or type of file I should be looking for. Sorry I am very new to this and haven't done anything C++ related in almost two years.


In that case, I'm sorry but I don't know what to tell you. Usually those errors are from missing .lib files but if none were included I have no clue.

Edit: Are there any .a files? Because that is another form of library.


No unfortunately this site only has the .cpp files and the .h files. I will have to search around for the libraries elsewhere.

One last question, is it possible that another compiler would not have these linker errors? IE: Borland Turbo, or some other type of compiler. If not I guess I will have to move to a different programming language and see if I can find something better from there.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.