wininet.h not compiling using GNU GCC compiler with code blocks - c++

i'm getting a peculiar issue when trying to compile my program. I don't have a huge ammount of experience with C++. I'm trying to simple create a function that can FTP put a file upto my plain FTP server. I'm using codeblocks IDE, and the GNU GCC compiler, and in the end, i thought to try a full fledged example i found online to test if it was me writing some silly code. I have installed the windows SDK with all libs, so i can confirm the files are present, and if i build without any code, there is no linker errors.
I copied the OP's code, as it looked fine, and he complained of no such issues.
http://social.msdn.microsoft.com/Forums/en-US/76eb8b89-4b96-41ba-b869-e30711f29256/ftpputfile?forum=vcgeneral
However when i attempt to build my project, i get a plethora of errors:
||=== Build: Debug in uploader (compiler: GNU GCC Compiler) ===|
C:\C++\uploader\main.cpp||In function 'void FileSubmit()':|
C:\C++\uploader\main.cpp|10|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
C:\C++\uploader\main.cpp|11|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
C:\C++\uploader\main.cpp|12|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetOpenA#20'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetConnectA#32'|
obj\Debug\main.o:main.cpp|| undefined reference to `FtpPutFileA#20'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetCloseHandle#4'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetCloseHandle#4'|
||=== Build failed: 5 error(s), 3 warning(s) (0 minute(s), 1 second(s)) ===|
Any idea what i'm doing wrong here? Do i need to be using certain compiler settings?

For anyone else experiencing this problem.
The solution to this, as implied by Igor in the commends on the op, was too manually add a link to the lib. In code blocks, this is accomplished by going to project --> Build Options, click the linker tab, and then manually browse to the file and include it. This has now made my project compile. Why code blocks requires this I don't know. But it does, so thanks Igor.

Related

Error: undefined reference to `typeinfo for veins::BatteryAccess'

I am getting this error in the Omnet++ project, based on the David Eckhoff Veins/Sumo Project.
The error is (maybe) because the version used in that omnet++ is 4.6 and the one I am using is the 5.0.
Nevertheless, I have been trying to find a logic solution to it without any success.
make MODE=debug all
src/TutorialAppl.cpp
In file included from src/TutorialAppl.cpp:3:
In file included from src/TutorialAppl.h:12:
In file included from C:/Users/konra/OneDrive/Escritorio/SUMO_VEINS_OMNET/veins-5.0/veins-veins-5.0/src\veins/modules/messages/WaveShortMessage_m.h:33:
C:/Users/konra/OneDrive/Escritorio/SUMO_VEINS_OMNET/veins-5.0/veins-veins-5.0/src\veins/base/utils/Coord.h:329:27: warning: 'veins::Coord::info' redeclared inline; 'dllimport' attribute ignored [-Wignored-attributes]
inline std::string Coord::info() const
^
1 warning generated.
Creating executable: out/clang-debug//VeinsTutorial_dbg.exe
out/clang-debug//src/TutorialAppl.o:(.rdata[_ZTIN5veins9BaseLayerE]+0x10): undefined reference to `typeinfo for veins::BatteryAccess'
out/clang-debug//src/TutorialAppl.o:(.rdata[_ZTIN5veins12BaseMobilityE]+0x10): undefined reference to `typeinfo for veins::BatteryAccess'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:101: out/clang-debug//VeinsTutorial_dbg.exe] Error 1
"make MODE=debug all" terminated with exit code 2. Build might be incomplete.
Oh, this is a compiler bug (clang).
The clang compiler does NOT mark the typeinfo symbols as exportable on Windows. This usually goes unnoticed unless you are trying to use an abstract class from a base project (veins) in a project that depends on it. Abstract classes are used regularly to define interfaces in Veins, INET and OMNeT++, too.
There is a workaround for this in INET that can be implemented also in your own project (and in veins too), but it is extremely ugly and it requires the re-linking of the library each time so link time increases heavily.
Other more straightforward workarounds:
Add -Wl,--export-all-symbols to the linker command line in Veins to force the exporting of ALL symbols. (Veins is small enough not to cause issues with the 65K limit for the number of exported symbols on Windows)
Use GCC instead of clang on Windows (you should rebuild omnet++, too)
Use Linux/macOS
Use static linking

MinGW in Code::Blocks not linking static OpenSSL Library

I'm trying to take advantage of some of OpenSSL's EC cryptography and ECDSA functionality to make a rudimentary blockchain simulation, but I've run into a major roadblock. I'm using the Code::Blocks IDE, and I've installed OpenSSL using the 64-bit binary found here: https://slproweb.com/products/Win32OpenSSL.html.
In Linker Settings, I added OpenSSL-Win64\lib\openssl.lib
In Search Directories > Compiler, I added OpenSSL-Win64\include
In Search Directories > Linker, I added OpenSSL-Win64\lib
However, when I compile, I get the "undefined reference to (function name)" error for every OpenSSL function I try to use. However, the compiler seems to be successfully including the header files, since it recognizes the new data types like EC_KEY. I suspect a linking error, but I'm not sure what could be wrong, since I have the link paths and static library linked as above.
Here is my build log:
mingw32-g++.exe -LD:\OpenSSL-Win64\lib -LD:\OpenSSL-Win64\include -LD:\OpenSSL-Win64 -o bin\Debug\BlockchainSim.exe obj\Debug\main.o obj\Debug\src\Block.o obj\Debug\src\BlockchainNode.o obj\Debug\src\Transaction.o obj\Debug\src\Valuable.o D:\OpenSSL-Win64\lib\openssl.lib
obj\Debug\src\BlockchainNode.o: In function `ZN14BlockchainNodeC2Ei':
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:18: undefined reference to `EC_KEY_new_by_curve_name'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:21: undefined reference to `BN_new'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:22: undefined reference to `EC_KEY_set_private_key'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:25: undefined reference to `BN_CTX_new'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:26: undefined reference to `BN_CTX_start'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:28: undefined reference to `EC_KEY_get0_group'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:29: undefined reference to `EC_POINT_new'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:30: undefined reference to `EC_POINT_mul'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:31: undefined reference to `EC_KEY_set_public_key'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:34: undefined reference to `EC_POINT_free'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:35: undefined reference to `BN_CTX_end'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:36: undefined reference to `BN_CTX_free'
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:37: undefined reference to `BN_clear_free'
obj\Debug\src\BlockchainNode.o: In function `ZN14BlockchainNodeD2Ev':
F:/School/Barrett/BlockchainSim/src/BlockchainNode.cpp:42: undefined reference to `EC_KEY_free'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
15 error(s), 0 warning(s) (0 minute(s), 0 second(s))
I'm hoping I'm just missing something simple here since I'm new to linking static libraries. A lot of similar issues seem to be solved by adding options to compile commands, but since I'm using Code::Blocks and linking OpenSSL as a static library, I'm not sure if those apply here. Any help is greatly appreciated.
Figured it out. The issue was that I had no C:/MinGW folder (as Code::Blocks installed MinGW within its own directory). I'm guessing the binary I used tries to detect existing compilers and compiles the library differently depending on what it finds.
I fixed it by installing default MinGW (with MSYS, in case that matters) with the default path (C:/MinGW) and then reinstalling the 32-bit binary OpenSSL linked in the original question, also in the default path (C:/OpenSSL-Win32). This made it so that within the C:/OpenSSL-Win32/lib folder, there was a new MinGW folder which I then included in the linker search directories.

Problems installing/understanding c++ libraries( novice programmer)

I have just started learning programming, and I am facing troubles adding libraries ( Other than STD libraries) in my programs.
I use codeblocks IDE and I wanted to add a library CImg from the internet.
After reading many threads I have done the following steps however I still get an error loading one of the examples provided CImg people
Downloaded Cimg folder which has a Cimg.h file along with other example files.
Unzip the folder to E drive.
open code blocks>compiler settings(gnu gcc compiler)>search libraries
under search libraries I have compiler tab and linker tab where I have added the path of the downloaded folder.
next when I open an example provided by the developer, build and run it.
The cimg.h file open up and I get the following error:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
E:\programming\cpp programming\CImg-2.0.0_pre012317\CImg.h||In function 'int cimg_library::cimg::fseek(FILE*, INT_PTR, int)':|
E:\programming\cpp programming\CImg-2.0.0_pre012317\CImg.h|5617|error: '_fseeki64' was not declared in this scope|
E:\programming\cpp programming\CImg-2.0.0_pre012317\CImg.h||In function 'INT_PTR cimg_library::cimg::ftell(FILE*)':|
E:\programming\cpp programming\CImg-2.0.0_pre012317\CImg.h|5626|error: '_ftelli64' was not declared in this scope|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 10 second(s)) ===|
Please help me out, Also kindly explain to me what I am doing as I have no idea.
EDIT: As pointed out to me in the comments I have changed my compiler to TDM-GCC MinGW 64 bit compiler.
But now I get a different type of error, is it because I havent installed the compiler properly because I can run hello world using this compiler.
the error that i get is :
||=== Build: Debug in hello (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function cimg_library::CImgDisplay::paint()':|
E:\programming\cpp programming\hello\..\CImg-2.0.0_pre012317\CImg.h|9696|undefined reference to__imp_SetDIBitsToDevice'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Finally I have found out what were my mistakes and how to correct them.
I was using a 32 bit compiler, So I switched to one for 64 bits.
After that I had not linked gdi32 library. So when I went to linker settings and added gdi32 to linked libraries evrything started to work.
Thank you for helping me out.

Linker can't find declared function in Glaux library

(I know it is similar to questions previously asked, but I tried for hours and failed to successfully use advice like the one written HERE and in related threads; I'm too inexperienced and a slow learner).
I'm Using:
Code::Blocks 13.12 IDE,
GNU GCC Compiler,
MinGW's folders for holding GLUT and
other libraries + files (like GLAux.h).
Windows 7 OS
Error message:
In function `Z7LoadBMPPc':
undefined reference to `auxDIBImageLoadA#4'
=== Build failed: 1 error(s), 5 warning(s) (0 minute(s), 3 second(s)) ===
(Testing one of the proposed solutions, when I additionelly add a Glaux library to the linker's libraries, dozens of other undefined reference errors pop up.)
The above function's declaration is in the <gl\GLAux.h> header file:
AUX_RGBImageRec * APIENTRY auxDIBImageLoadA(LPCSTR);
But naturally I can't go further, and look into the Glaux library itself.
I only know how to solve (some) undefined reference problems if they refer to the code I've written. Here it is not the case.
.
Which version of the undefined reference problem am I dealing with?
What to do?
Project → Build options → Linker Settings → Add → GLAUX → OK. Also you need to specify the full link to the picture. And pucture must be BMP 24 bit.

wxwidgets // g++ Compiler error: no matching function for call to 'operator new(..'

At the moment I am trying to port a Visual C++ application to Linux. The code compiles without errors in Visual Studio, but I get many compiler errors under Linux. One of these errors is:
../src/wktools4.cpp:29: error: no matching function for
call to 'operator new(unsigned int, const char[40], int)'
More information:
IDE: kdevelop with G++
GUI API:
The error appears at the following line:
IMPLEMENT_APP(Cwktools4App)
and some other lines.
What am I missing?
I found the error:
#ifdef __WXDEBUG__
#define new WXDEBUG_NEW
#endif
When I remove these lines, I don't get the errors any more. The code was generated from a wxwidgets wizard for VisualStudio. I have no idea what it does...
Thank you all for your help! Now I have to fix the linker errors ;)
It looks like your Visual C++ app has overloaded operator new().
This is often done (with the additional parameters you see) to add debugging and other analysis info to each memory allocation.
Since you get the error with something as simple as frame = new Cwktools4Frame; I recommend looking for macros or compiler-level defines that are redefining "new" as something else. The first place to look should be in debug-specific builds.