Can't compile this code [duplicate] - c++

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?
I have troubles with compiling this code http://pastebin.com/a7AMbYPv.
Here are the errors I get:
C:\Dev-Cpp\include\main.cpp In function 'int write_jpeg_file(char*)':
109 25 C:\Dev-Cpp\include\main.cpp [Error] invalid conversion from 'int' to 'J_COLOR_SPACE' [-fpermissive]
C:\Dev-Cpp\include\main.cpp In function 'int main()':
130 21 C:\Dev-Cpp\include\main.cpp [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
130 48 C:\Dev-Cpp\include\main.cpp [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
C:\Users\NIVER\Desktop\Makefile.win [Error] [../../../Dev-Cpp/include/main.o] Error 1 (if this is the only error: please check your library includes)
Any help would be appreciated.

In your code you have reference to functions that you do not implement them (jpeg_std_error, ...), so you must provide their implementation to the linker. this is usually done with adding a .lib or .a or something like that to list of inputs of your linker. please look where you get the sample and get its implementation of those functions (either a source C/C++) files or get its compiled library (in form .lib or .a) and add them to the linker with flags that specified for your linker and every thing will work as expected

Related

What the underlying reason C code will compile using mingw32 in Linux but Visual Studio C has problems

So Im wondering why C code compiled for me with mingw32 (this program here fo reference https://github.com/newsoft/adduser) with no issues or mentions of errors (other than some case-sensitivity in naming of the headers i mean)
Though, when I tried in Visual Studio 2019 I get the following "errors" that need to be cleaned up.
Error C2440 '=': cannot convert from 'const wchar_t [15]' to 'LPWSTR' adduser-test2 C:\Users\Administrator\source\repos\adduser-test\adduser-test2\adduser-test2.cpp 39
Error C2440 '=': cannot convert from 'const wchar_t [6]' to 'LPWSTR' adduser-test2 C:\Users\Administrator\source\repos\adduser-test\adduser-test2\adduser-test2.cpp 38
Is it some sort of strict compiler settings for "safer code"? Or is one compiler actually just able to convert a const wchar_t could convert to a pointer to a wchar_t if necessary

Why can't I import header files to a library in one of my header files?

I'm using the C++ socket.io library in my C++ project, and I'm unable to include the required header files in my projects header file.
But when I include the required header files in my CPP file, I am successfully able to include the required header files.
Steps taken to utilize the library:
Compile the C++ websocketpp, openssl, boost library, and prepare the JSON library.
Link against the *.lib files in my VS2015 project.
Include the header files location in the C++ additional include dependencies folder.
Include the *.lib files location in the Linker include dependencies folder.
Include the three header files in my CPP file.
Build. Yay! It works!
Attempt to encapsulate the libraries functionality into my own class/object.
Attempt to include the three libraries header files in my header file. Notice a plethora of compilation errors about initializing.
Header File Import
#include <sio_message.h>
#include <sio_socket.h>
#include <sio_client.h>
Error when including header files within header file:
Severity Code Description Project File Line Suppression State
Error C2440 'initializing': cannot convert from 'nullptr' to 'const int &' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'function<void __cdecl(sio::message::list const &)>': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'function<void __cdecl(sio::message::list const &)>': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2440 'initializing': cannot convert from 'nullptr' to 'const int &' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'list': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'list': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2439 'sio::socket::ack': member could not be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2439 'sio::socket::ack': member could not be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2439 'sio::socket::msglist': member could not be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2439 'sio::socket::msglist': member could not be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2530 'sio::socket::name': references must be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 96
Error C2530 'sio::socket::name': references must be initialized c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 96
Error C2838 'string': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2838 'string': illegal qualified name in member declaration c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2059 syntax error: ')' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2059 syntax error: ')' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2143 syntax error: missing ')' before 'const' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2143 syntax error: missing ')' before 'const' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2143 syntax error: missing ';' before 'const' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Error C2143 syntax error: missing ';' before 'const' c:\root\src\socket.io-client-cpp\build\include\sio_socket.h 75
Possible Problems:
Shared Namespace? Maybe I'm propagating an incorrect namespace?
Circular Dependencies? Maybe I'm causing a circular dependency by including the header files in my class, and one of the other header files are including that same file.
Solution:
I figured out what the problem happened to be. Both the Socket.io C++ library and Qt share namespace in regards to the word "emit". In the event that somebody else runs into this problem here is how I resolved it:
git clone https://github.com/raksa/SocketIO-cpp-lib
Edit all instances of the term "emit" in the source files. In my case I changed them all to "emit_signal".
git checkout development within the websocketpp library. (Wouldn't compile on master or from the most recent tag as of 2/16/2017).
Recompile the sioclient.lib file from the SocketIO-cpp-lib project for both debug and release.
Go to your project and link against the lib file. Also, provide the lib file path.
Include the sioclient.h, siosocket.h, and siomessage.h file's directory to your include path.
Include both the boost libraries path and boost libraries *.lib files to your project.
You shouldn't have errors when including any of the Socket.io C++ header files in your project.
Hope this helps anybody else with the same issue.
Note: I also ran into another problem when building the sioclient.lib file. You might need to make an "optimized" and "debug" folder in one of the project folders. The CMAKE script incorrectly references folders that don't exist in the project. That, or delete those lines from the CMAKE script.

How to import existing OpenSsl project into Xcode

I would like to modify the existing Openssl project. So I downloaded the source code of openssl from GitHub https://github.com/openssl/openssl
and follow the instruction http://openssl.6102.n7.nabble.com/Easy-inclusion-of-OpenSSL-into-iOS-projects-agileinfoways-com-td48905.html on how to include Openssl into Xcode.
However, when i tried to build one of the file (enc.c) from OpenSsl project, it run into 6 errors and 7 warning.
/usr/local/opt/openssl/include/openssl/ecdsa.h
/usr/local/opt/openssl/include/openssl/ecdsa.h:295:14: Parameter
'flags' not found in the function declaration
/usr/local/opt/openssl/include/openssl/ecdsa.h:301:14: Parameter
'ecdsa_method' not found in the function declaration
/usr/local/opt/openssl/include/openssl/ecdsa.h:302:14: Parameter 'name' not found in the function declaration
/Users/maggie/Documents/aes/openssl-master/apps/apps.h
/Users/maggie/Documents/aes/openssl-master/apps/apps.h:421:1: Unknown type name '__owur'
/Users/maggie/Documents/aes/openssl-master/apps/apps.h:421:8: Expected identifier or '('
/Users/maggie/Documents/aes/openssl-master/apps/apps.h:432:1: Unknown type name '__owur'
/Users/maggie/Documents/aes/openssl-master/apps/apps.h:432:8: Expected identifier or '('
/Users/maggie/Documents/aes/openssl-master/apps/progs.h
/Users/maggie/Documents/aes/openssl-master/apps/progs.h:25:1: Type specifier missing, defaults to 'int'
/Users/maggie/Documents/aes/openssl-master/apps/enc.c
/Users/maggie/Documents/aes/openssl-master/apps/enc.c:542:47: Expected ')'
/Users/maggie/Documents/aes/openssl-master/apps/enc.c:543:47: Expected ')'
/Users/maggie/Documents/aes/openssl-master/apps/enc.c:427:33: Implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int'
/Users/maggie/Documents/aes/openssl-master/apps/enc.c:597:28: Implicit declaration of function 'OPENSSL_hexchar2int' is invalid in C99
/Users/maggie/Documents/aes/openssl-master/apps/enc.c:582:9: Implicit conversion loses integer precision: 'unsigned long' to 'int'
Source code of enc.c is here
Does anyone ever encounter this problem?
Thanks.

error C2440: 'type cast' : cannot convert from 'unsigned int (__thiscall IEngineVGui::* )(unsigned int)' to 'void *'

So i'm trying to port my friends code that was compiled with GCC to Visual C++.
Your problem lies here:
(void*) &IEngineVGui::GetPanel
The type of &IEngineVGui::GetPanel is int (IEngineVGui::*) (int), which is a member function pointer.
You are trying to convert it to a "regular" pointer type, which is sadly not possible because they are handled completely differently. So MSVC is acting correctly by giving you an error. If your code compiled fine on GCC, it was most likely due to a bug and/or a non-standard extension in that particular version.

How can I use CLAPACK,BLAS or LAPACK in a mex file?

I am having trouble writing a MEX file in MATLAB that can perform a simple linear operation such as taking the inverse of a matrix. I have successfully managed to take the inverse of a matrix using Visual Studio 2010 and have successfully created a MEX file hence the only thing I am having trouble is getting these two concepts together. I have tried to compile a MEX example code that I got from the MathWorks site but with no luck.
Here is what I have tried,
Saved the file (renamed it) I got from MathWorks as .c extension and then tried to compile it in MATLAB got:
Creating library C:\Users\CIT\AppData\Local\Temp\mex_bKHjrl\templib.x
and object C:\Users\CIT\AppData\Local\Temp\mex_bKHjrl\templib.exp
eko1.obj : error LNK2019: unresolved external symbol dgesv referenced
in function mexFunction eko1.mexw64 : fatal error LNK1120: 1
unresolved externals
Also I tried to compile it as a .cpp file however an error occurred because it didnt recognize the memcpy function.
Since these didn't work I wrote my own program that used the subroutines dgetrf and dgetri from the LAPACK library however an error occured:
c:\users\cit\documents\matlab\f2c.h(16) : error C2371: 'complex' :
redefinition; different basic types
C:\Program Files\MATLAB\R2011b\extern\include\lapack.h(39) : see declaration of 'complex' c:\users\cit\documents\matlab\f2c.h(17)
: error C2371: 'doublecomplex' : redefinition; different basic types
C:\Program Files\MATLAB\R2011b\extern\include\lapack.h(40) : see declaration of 'doublecomplex' eko2.cpp(29) : error C2057:
expected constant expression eko2.cpp(29) : error C2466: cannot
allocate an array of constant size 0 eko2.cpp(29) : error C2133:
'ipiv' : unknown size eko2.cpp(33) : error C2664: 'dgetrf' : cannot
convert parameter 1 from 'integer *' to 'ptrdiff_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast eko2.cpp(34) :
error C2664: 'dgetri' : cannot convert parameter 1 from 'integer *' to
'ptrdiff_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Any help you guys give me would be extremely appreciated
Thanks in advance.
Without any code to see what you've tried, it's hard to tell, but... in order to properly compile a mex file in matlab that depends on other libraries, you need to specify those libraries in the compile command. Use mex filename.c -v -l*libraryname*.lib. The -l switch indicates to the compiler that you are specifying a library that you want to include. If this library is not found, I would include the full path to the library in the command. I hope that provides you with some assistance. Using this methodology has been successful for me.