Fatal error LNK1120: unresolved externals, caused by C functions in C++

I was receiving link error LNK1120 in Visual Studio after adding some C code to my C++ project, and the problem was, as I discovered here (and found more info on here), that I hadn’t declared my C code as “extern C”.

So basically I added #ifdef __cplusplus macros to check if it was C or C++ code and if C++ then outputting “extern C {” with a suitable “}” at the end of the file.

Compiler Error C2662

I was forced to lookup Visual Studio’s Compiler Error C2662 because I was getting it in my code. Turns out this happens when your const’s don’t line up. In my case I had const in the client declaration but the member function I was calling didn’t have the const specification.

This little nugget of code from the referenced article shows how to fix up the problem:

// C2662.cpp
class C {
public:
   void func1();
   void func2() const{}
} const c;

int main() {
   c.func1();   // C2662
   c.func2();   // OK
}

Failed To Read Auto-Increment Value From Storage Engine – MySQL

Recently after my hosting provider hard-booted one of my machines the MySQL service started to complain “Failed To Read Auto-Increment Value From Storage Engine” when an insert was issued to any table with an auto increment field. I found the solution here, and it basically requires you to reset the auto increment key on the table, like this:

ALTER TABLE `table_name`  AUTO_INCREMENT =1

I had to do that on all of my tables that had auto increment keys to resolve the issue.