Compiling Mathlink Code in Visual Studio 2010 Express LNK2019 Error - c++

I'm attempting to compile a simple C file for use with Mathematica. (Note: I did follow the rest of the instructions, creating the empty addtwotm.c file and adding addtwo.tm)
#include "mathlink.h"
extern int addtwo( int i, int j);
int addtwo( int i, int j)
{
return i+j;
}
#if WINDOWS_MATHLINK
#if __BORLANDC__
#pragma argsused
#endif
int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow)
{
char buff[512];
char FAR * buff_start = buff;
char FAR * argv[32];
char FAR * FAR * argv_end = argv + 32;
hinstPrevious = hinstPrevious; /* suppress warning */
if( !MLInitializeIcon( hinstCurrent, nCmdShow)) return 1;
MLScanString( argv, &argv_end, &lpszCmdLine, &buff_start);
return MLMain( (int)(argv_end - argv), argv);
}
#else
int main(int argc, char* argv[])
{
return MLMain(argc, argv);
}
#endif
However, on build, I get this output:
1>------ Build started: Project: addtwo, Configuration: Debug Win32 ------
1> Performing Custom Build Tools
1> on "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\VC\bin\mprep.exe" "" -o "D:\Applications\Mathematica\SystemFiles\Links\MathLink\DeveloperKit\Windows\MathLinkExamples\addtwo\addtwo\..\addtwotm.c"
1>addtwo.obj : error LNK2019: unresolved external symbol _MLMain referenced in function _WinMain#16
1>addtwo.obj : error LNK2019: unresolved external symbol _MLInitializeIcon referenced in function _WinMain#16
1>D:\Applications\Mathematica\SystemFiles\Links\MathLink\DeveloperKit\Windows\MathLinkExamples\addtwo\Debug\addtwo.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I've followed all provided instructions from Wolfram's MathLink Developer Guide, and made sure to add "ml32i3m.lib" to Linker>Input>Additional Dependencies. Supposedly the ml32/ml64 lib files contain the information for MlMain. Any help is appreciated :)

Related

How to connect OpenMPI library to Visual Studio 2015

I need to connect OpenMPI library to Visual Studio 2015. I can't use other liblaries instead of OpenMPI. I setup OpenMPI_v1.6.2-1_win32.exe and specified:
Include Directories: C:\Program Files\OpenMPI_v1.6.2-win32\include
Library Directories: C:\Program Files\OpenMPI_v1.6.2-win32\lib
Additional Dependencies: libmpi.lib
Open MP Support: Yes
When I try to compile the code:
#include <stdio.h>
#include "mpi.h"
int main(int argc, char* argv[]) {
int ProcNum, ProcRank, RecvRank;
MPI_Status Status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &ProcNum);
MPI_Comm_rank(MPI_COMM_WORLD, &ProcRank);
if (ProcRank == 0) {
// Действия, выполняемые только процессом с рангом 0
printf("\n Hello from process %3d", ProcRank);
for (int i = 1; i < ProcNum; i++) {
MPI_Recv(&RecvRank, 1, MPI_INT, MPI_ANY_SOURCE,
MPI_ANY_TAG, MPI_COMM_WORLD, &Status);
printf("\n Hello from process %3d", RecvRank);
}
}
else // Сообщение, отправляемое всеми процессами,
// кроме процесса с рангом 0
MPI_Send(&ProcRank, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
Visual Studio show errors:
1>------ Build started: Project: OpenMPISample, Configuration: Debug
Win32 ------ 1>Source.obj : error LNK2001: unresolved external symbol
_ompi_mpi_comm_world 1>Source.obj : error LNK2001: unresolved external symbol _ompi_mpi_int 1>C:\Users\Andriy\Documents\Visual Studio
2015\Projects\OpenMPISample\Debug\OpenMPISample.exe : fatal error
LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How to connect OpenMPI library to Visual Studio 2015 correctly? Thanks in advance!

Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt' on Visual Studio 2010 C ++? [duplicate]

This question already has answers here:
error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
(13 answers)
Closed 9 years ago.
I get the following error Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt' when I compile my code using Win32 Console Application.
I tried fixing it my going into Projects -> Properties -> General -> Linker -> Enable Incremental Linking and I changed it from "Yes" to No (/INCREMENTAL:NO) and then I tried to debug my code again but got another error message :
1>------ Build started: Project: Someproject, Configuration: Debug Win32 ------
1>project1.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
1>c:\users\anne\documents\visual studio 2010\Projects\Someproject\Debug\Someproject.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How can I fix it?
#include <Windows.h>
#include <process.h>
#include <stdio.h>
#include <math.h>
volatile int counter = 0;
int isPrime(int n)
{
for(int i = 2; i < (int)(sqrt((float)n) + 1.0) ; i++) {
if (n % i == 0) return 0;
}
return 1;
}
unsigned int __stdcall mythread(void*)
{
char* s;
while (counter < 25) {
int number = counter++;
s = "No";
if(isPrime(number)) s = "Yes";
printf("Thread %d value = %d is prime = %s\n",
GetCurrentThreadId(), number, s);
}
return 0;
}
int main(int argc, char* argv[])
{
HANDLE myhandleA, myhandleB;
myhandleA = (HANDLE)_beginthreadex(0, 0, &mythread, (void*)0, 0, 0);
myhandleB = (HANDLE)_beginthreadex(0, 0, &mythread, (void*)0, 0, 0);
WaitForSingleObject(myhandleA, INFINITE);
WaitForSingleObject(myhandleB, INFINITE);
CloseHandle(myhandleA);
CloseHandle(myhandleB);
getchar();
system("pause");
return 0;
}
The basic problem is that you somehow specified "windows app" in your project settings. You want "console app" instead.
Windows apps use "WinMain()"; console apps use "main()".
Look at this link for details:
error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
See also:
Building Console Applications

OpenSSL fatal error LNK1120: 3 unresolved externals

I've installed OpenSSL to Windows 8, and did the necessary modifications to the OpenSSL library, without installing it as a native library. But I've a specific error message that I couldn't find it on internet.
1>------ Build started: Project: CryptoProject, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol _BN_new referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _BN_bn2dec referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _BN_generate_prime referenced in function _main
1>C:\Users\...\...\...\Debug\EXAMPLE.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hope you guys find something. So here it goes:
#include <iostream>
#include <string>
#include "openssl/bn.h"
using namespace std;
int main()
{
BIGNUM * q = BN_new();
BIGNUM * two = BN_new();
long int num_bits_q = 160;
long int num_bits_p = 1024;
BN_generate_prime(q, num_bits_q, 0, two, NULL,NULL,NULL);
cout << "q is: " << BN_bn2dec(q) << endl;
return 0;
}
I ran that code and it compiled successfully in visual studio 2012, I used OpenSSL-Win32. If OpenSSL-Win64 does not work use OpenSSL-Win32, I also had the same problem. Don't forget to include ssleay32.lib, I hope you know how to configure OpenSSl in visual studio.

SDL error LNK1120: 1 unresolved externals

am trying to test SDL using this codes :
#include <SDL.h>
int main(int argc, char** argv){
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface * screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
bool IsRuning = true;
Uint32 Start;
SDL_Event Event;
while (IsRuning)
{
Start = SDL_GetTicks();
while (SDL_PollEvent(&Event))
{
switch (Event.type)
{
case SDL_QUIT:
IsRuning = false;
break;
default:
break;
}
}
if(1000/30 > (SDL_GetTicks() - Start))
SDL_Delay(1000/30 > (SDL_GetTicks() - Start));
}
SDL_Quit();
return 0;
}
and am linking this libs :
SDLmain.lib
SDL.lib
OpenGL32.lib
glu32.lib
when am trying to debug it it gives me those errors :-
Warning 1 warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library c:\Users\administrator\documents\visual studio 2010\Projects\TestSDL\TestSDL\MSVCRTD.lib(cinitexe.obj)
Error 2 error LNK2019: unresolved external symbol ___report_rangecheckfailure referenced in function _redirect_output c:\Users\administrator\documents\visual studio 2010\Projects\TestSDL\TestSDL\SDLmain.lib(SDL_win32_main.obj)
Error 3 error LNK1120: 1 unresolved externals c:\users\administrator\documents\visual studio 2010\Projects\TestSDL\Debug\TestSDL.exe 1
what ma missing here?!!
Probably one of SDLmain.lib or SDL.lib links against msvcrt.lib, which is the MicroSoft Visual C RunTime library. However you're compiling a debug build, and debug builds depend on the debug variant of the runtime library. Those two runtime libraries, they are conflicting.
The solution would be to use specific debug builds of the SDL libraries.
I had the same issue. You need to change the line:
int main(int argc, char** argv)
to
int main(int argc, char* argv)

error LNK2019: unresolved external symbol

Ok, so I'm having a problem trying figure out the problem in my code. I have a lot of code so I'm only going to post the relevant parts that are messing up when I compile. I have the following function inside of a class and it will compile and everything will run fine until I call the function "CalculateProbabilityResults" and it runs the 7th line of code within it. I've "de-commented" this line of code in my program so you can find it easier. I'm pretty sure I have the right #include directives needed since it compiles fine when not calling the function, so that can't be the problem can it? I know some of my naming notation needs a little help, so please bear with me. Thanks in advance for the help guys.
int SQLServer::CalculateProbabilityResults(int profile, int frame, int time_period, int TimeWindowSize) {
ofstream ResultFile;
stringstream searchFileName;
stringstream outputName;
vector<vector<int>> timeFrameItemsets;
int num = getTimeFrameFile(frame*TimeWindowSize, TimeWindowSize);
cout << num << endl;
//outputName << "Results" << getTimeFrameFile((frame*TimeWindowSize), TimeWindowSize) << ".csv";
cout << outputName.str() << endl;
outputName.clear();
//ResultFile.open(outputName.str().c_str());
ResultFile.close();
result.resize(0);
return 0;
}
int getTimeFrameFile(int timeInHours, int timeFrameSize) {
int fileNum = 0;
int testWin;
if (timeInHours > 24) {
while (timeInHours >24)
timeInHours -= 24;
}
for (testWin = 0; testWin < 24/timeFrameSize; testWin++) {
if (timeInHours >= testWin*timeFrameSize && timeInHours < (testWin+1)*timeFrameSize)
fileNum = testWin+1;
}
if (fileNum == 0)
fileNum = testWin+1;
return fileNum;
}
Call Log
1>------ Rebuild All started: Project: MobileSPADE_1.3, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'MobileSPADE_1.3', configuration 'Debug|Win32'
1>Compiling...
1>main.cpp
1>MobileSPADE.cpp
1>SQLServer.cpp
1>Generating Code...
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>LINK : C:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\Debug\MobileSPADE_1.3.exe not found or not built by the last incremental link; performing full link
1>SQLServer.obj : error LNK2019: unresolved external symbol "public: int __thiscall SQLServer::getTimeFrameFile(int,int)" (?getTimeFrameFile#SQLServer##QAEHHH#Z) referenced in function "public: int __thiscall SQLServer::CalculateProbabilityResults(int,int,int,int)" (?CalculateProbabilityResults#SQLServer##QAEHHHHH#Z)
1>C:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\Debug\MobileSPADE_1.3.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\JoshBradley\Desktop\MobileSPADE_1.3\MobileSPADE_1.3\MobileSPADE_1.3\Debug\BuildLog.htm"
1>MobileSPADE_1.3 - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
The compiler thinks that getTimeFrameFile is a SQLServer method:
unresolved external symbol "public: int __thiscall SQLServer::getTimeFrameFile(int,int)"
but you have it defined as a free function:
int getTimeFrameFile(int timeInHours, int timeFrameSize) {
Change that from a free function to a class method will solve the problem:
int SQLServer::getTimeFrameFile(int timeInHours, int timeFrameSize)
Put the function getTimeFrameFile above SQLServer::CalculateProbabilityResults.