I have a problem compiling c-source on windows. I use functions of wininet and got a linker error.
I use this version g++.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
sample code:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wininet.h>
int main (int argc, char **argv)
{
InternetOpen("WebReader", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
return 0;
}
the compile statement wirh error:
"C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe" -lwininet -g test.c -o test.exe
C:\Users\peter\AppData\Local\Temp\ccfXocKI.o: In function `main':
D:\source\mingw\ShellHost/test.c:9: undefined reference to `_imp__InternetOpenA#20'
collect2.exe: error: ld returned 1 exit status
Can anyone help?
You should link with Wininet.lib as InternetOpenA documentation says (see Requirements part).
I realize this was posted almost two years ago, but I wanted to expand on nevilad's answer to help someone in the future:
As nevilad said, adding the Wininet library as an additional dependency should fix this issue.
In Visual Studios IDE... Project > Properties > Configuration Properties > Linker > Input > Additional Dependencies > add "Wininet.lib" to the list
Related
I am looking for a way to use cufft.h a CUDA toolkit which perform GPU parallelization of fast fourier transform.
First of all, I downloaded cuda library and cufft through synaptic.
Then I used the sample program from the cufft documentation from NVidia.
my cuda library is located at /usr/local/cuda-9.0 on my laptop.
I added those include :
1 #include <iostream>
2 #include <cstdio>
3 #include "/usr/local/cuda-9.0/include/cuda.h"
4 #include "/usr/local/cuda-9.0/include/cuda_runtime_api.h"
5 #include "/usr/local/cuda-9.0/include/cufft.h"
I compile like this :
g++ -Wall main.cpp -o main
and get undefine references error for each cuda-like functions (cudaMalloc,cudaGetLastError, etc...)
I am pretty young about library implementation and I don't understand what should I do to include properly this cuda-cufft library...
The nvidia documentation talk about filename.cu but I don't know what this is about...
Thank you for your time :)
n.b : I added cuda.h and cuda_runtime_api.h after reading a forum (I forgot which it was). Apparently, only cuda_runtime_api.h is necessary (I tried without cuda.h and get the same errors).
Here is a complete sample code (that doesn't do anything useful) and a sample g++ compile command that will properly compile and link the code:
$ cat t1338.cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cuda_runtime.h>
#include <cufft.h>
int main() {
size_t work_size;
int fft_sz = 32; // Size of each FFT
int num_ffts = 1; // How many FFTs to do
cufftComplex *in_buf_h, *in_buf_d, *out_buf_d;
// Allocate buffers on host and device
in_buf_h = new cufftComplex[fft_sz*num_ffts];
cudaMalloc(&in_buf_d, fft_sz*num_ffts*sizeof(cufftComplex));
cudaMalloc(&out_buf_d, fft_sz*num_ffts*sizeof(cufftComplex));
cudaMemset(out_buf_d, 0, fft_sz*num_ffts*sizeof(cufftComplex));
// Fill input buffer with zeros and copy to device
memset(in_buf_h, 0, fft_sz*num_ffts*sizeof(cufftComplex));
cudaMemcpy(in_buf_d, in_buf_h, fft_sz*num_ffts*sizeof(cufftComplex), cudaMemcpyHostToDevice);
// Plan num_ffts of size fft_sz
cufftHandle plan;
cufftCreate(&plan);
cufftMakePlan1d(plan, fft_sz, CUFFT_C2C, num_ffts, &work_size);
// Execute the plan. We don't actually care about values.
cufftExecC2C(plan, in_buf_d, out_buf_d, CUFFT_FORWARD);
// Sync the device to flush the output
cudaDeviceSynchronize();
return 0;
}
$ g++ t1338.cpp -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lcudart -lcufft
$
Your include statements are probably OK as-is, but I have used a format that says "search on the standard path for this file" and then I identify an addition to the standard path with
-I/usr/local/cuda/include
However your compile command is definitely missing the necessary link apparatus. You need to specify where to find the libraries (the path) with -L and then indicate the specific libraries to include, which are both the CUDA runtime library (-lcudart) and also the CUFFT library (-lcufft):
-L/usr/local/cuda/lib64 -lcudart -lcufft
The CUDA toolkit normally gets installed with sample codes which will have sample Makefiles you can inspect, or just compile those projects to see typical compilation command usage.
As I mentioned, this source code is incomplete. It doesn't do anything useful. It is just to demonstrate proper compilation behavior. In particular, I've omitted proper error checking, which I recommend you include in your actual codes.
Depending on whether your install created a symbolic link or not, you may need to change the above paths to:
-I/usr/local/cuda-9.0/include
and
-L/usr/local/cuda-9.0/lib64 -lcudart -lcufft
I'm trying to use ImageMagick Library for a C Project in VS2012. I installed the Library from here: klick
Then in my Project, I added D:\Program Files (x86)\ImageMagick-6.9.1-Q16\include\ to the include folders.
Then I tried to use Magick with an example code from here:
[http://www.graphicsmagick.org/1.2/www/api.html]
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <magick/api.h>
int main(int argc,char **argv)
{
InitializeMagick(*argv);
GetExceptionInfo(&exception);
... ...
}
Then VS2012 returns errors when I try to compile:
error C3861: “InitializeMagick”: identifier not found
error C3861: “GetExceptionInfo”: identifier not found
error C3861: “DestroyMagick”: identifier not found
Is there any steps I missed?
Thanks very much for your help!
You need to add the .lib files to the linker.
Like setting the header include, open Properties -> Linker -> Additional Library Directories, and add path to .lib files. Then add CORE_RL_magick_.lib & CORE_RL_wand_.lib files to be linked against.
An even easier approach.
Just drag and drop said .lib's from explore into the Solution Explorer.
I'm programming c++ in Borland c++ 5.02. I'm trying to run this code:
#include <stdio.h>
#include <pthread.h>
#define NUM 5
main()
{
pthread_t t1, t2; /* two threads */
void *print_msg(void *);
pthread_create(&t1, NULL, print_msg, (void *)"hello");
pthread_create(&t2, NULL, print_msg, (void *)"world\n");
pthread_join(t1, NULL);
pthread_join(t2, NULL);
}
But I get this error:
Info :Compiling C:\BC5\BIN\noname00.cpp
Error: noname00.cpp(2,2):Unable to open include file 'PTHREAD.H'
Error: noname00.cpp(8,15):Undefined symbol 'pthread_t'
Error: noname00.cpp(8,15):Statement missing ;
Error: noname00.cpp(12,18):Call to undefined function 'pthread_create'
I highlighted the main error which is caused by 'PTHREAD.H'. I checked the include folder for this file. It doesn't exist. How can I fix this problem?
Borland's C++ toolchain doesn't include a pthreads library, nor does the Windows SDK. You'll either need to use native Win32 thread APIs or get a 3rd party pthreads implementation for Windows.
Some options include:
winpthreads.h: http://locklessinc.com/articles/pthreads_on_windows/
pthreads-win32: https://www.sourceware.org/pthreads-win32/
I have no idea how well those things work with Borland C++ 5.x.
Another alternative is to use a toolchain that includes a pthreads implementation, such as TDM's MinGW toolchain:
http://tdm-gcc.tdragon.net/
your problem is #include <pthread.h>
you need either copy all the pthread related files (.h,.c,.cpp,.hpp,.lib,.obj)
into compiler include folder
or add include path to it in your project/compiler settings
or copy it locally to your project and change #include <pthread.h> to #include "pthread.h"
So compiler did not find the pthread.h header
so no datatype from it is known from compiler side (like pthread_t)
therefore the rest of the errors...
I am trying to write a program using FFMPEG libraries. I read about in this link. I downloaded Shared and Devs files from http://ffmpeg.zeranoe.com/builds/.
I created a console project and this is the configuration:
Additional Libraries Directories
Additional Include Directories
And here is my code:
#include "stdafx.h"
#pragma comment (lib, "avformat.lib")
#pragma comment (lib, "avcodec.lib")
#pragma comment (lib, "avutil.lib")
extern "C"
{
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#include <libavcodec\avcodec.h>
#include <libavformat\avformat.h>
#include <libswscale\swscale.h>
#include <libavutil\avutil.h>
}
int _tmain(int argc, _TCHAR* argv[])
{
av_register_all();
return 0;
}
And the error I am getting is this:
Error 1 error LNK2019: unresolved external symbol _av_register_all
referenced in function _wmain C:\Users\Andres\Documents\Visual Studio
2013\Projects\PruebaFFMPEG\PruebaFFMPEG\PruebaFFMPEG.obj PruebaFFMPEG
Error 2 error LNK1120: 1 unresolved
externals C:\Users\Andres\Documents\Visual Studio
2013\Projects\PruebaFFMPEG\Debug\PruebaFFMPEG.exe PruebaFFMPEG
What am I missing?
It seems that you are trying to link a 32-bit application with 64-bit libraries. Download 32-bit libraries from http://ffmpeg.zeranoe.com/builds/ or create x64 configuration for your solution.
I'm using RHEL5 kernel 2.6.33 and running GCC v4.1.2.
During my program compilation, I get the warning "implicit declaration of function CPU_ALLOC" and the error "undefined reference to 'CPU_ALLOC'. I get the same warnings and errors for CPU_ZERO_S, CPU_SET_S, CPU_FREE, numa_bitmask_alloc, numa_bitmask_setbit and numa_bitmask_free.
I understand that CPU_ALLOC should be found in sched.h, but I've searched several sched.h (/usr/include/sched.h, /usr/include/bits/sched.h, /usr/include/linux/sched.h, /usr/src/kernels/linux-2.6.33.1/include/linux/sched.h), and cannot find CPU_ALLOC.
I have tried both #include <sched.h> and #include "/usr/include/sched.h", but I still have the errors.
I found declarations of CPU_ALLOC and the other functions on this website. Is this a file that I should have on my system?
How do I resolve this problem with the CPU_* and numa_bitmask_* functions?
Thank you.
Regards,
Rayne
You need to include the following in your header file containing CPU_ALLOC.
#define _GNU_SOURCE
#include <sched.h>