I'm trying to run a Visual Studio cpp project created by a friend of mine. I'm trying to run the file without VS. But I'm getting a list of errors, all in the same format:
inlining failed in call to always_inline '__m256d _mm256_broadcast_sd(const double*)': target specific option mismatch|
It runs correctly in VS with release mode and breaks when run in debug mode.
The includes are as follows:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
# include <omp.h>
#include <chrono>
#include <fstream>
#include <algorithm>
#include <immintrin.h>
using namespace std::chrono;
using namespace std;
and the error is called from here:
double zero = 0;
__m256d acc = _mm256_broadcast_sd(&zero);
Update:
I'm using the this command to run it: g++ -std=c++0x multip.cpp -o multip, is there an additional parameter to add -mavx to the compiler invocation?
"Target specific option mismatch" means that you're missing a feature flag from your GCC invocation. You probably need to add -mavx to your compiler invocation.
If you're intending to run this on your computer only, -march=native will turn on all the feature flags that your own machine supports.
Related
I downloaded tdm gcc 10.3.0 and installed it succesfully. I have a file I want to compile yet it is missing header files. Is there a way to add components to tdm gcc from an interface, or do I download the files(headers) manually and add them to the project. If so, where do I add them in the project ? I know header files exist in C:\TDM-GCC-32\include
Also, just in case, I have these header files in my main.c,
#include <winsock2.h>
#include <Windows.h>
#include <ws2ipdef.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <bcrypt.h>
#include <wincrypt.h>
#include <sysinfoapi.h>
#include <winternl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
as i tried to compile with gcc main.c, I got this error
main.c:8:10: fatal error: ws2ipdef.h: No such file or directory
8 | #include <ws2ipdef.h>
| ^~~~~~~~~~~~
compilation terminated.
How can I find this header file? If I just find it in github is it enough to add it to C:\TDM-GCC-32\include ?
another way to ask, how can I add ws2 to tdm gcc, or how to install tdm gcc alongwith?
I am trying to parallelize an algorithm in C. I want to use pthread_barrier_t but my Ubuntu wsl can't find it for some reason. I have pthread.h included and I can use the rest of the pthread functions. libthread.a is installed.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
/* Error occurs here */
pthread_barrier_t barrier;
Exact error is: "identifier pthread_barrier_t is undefined"
I saw elsewhere it could be the way I'm compiling.
Compiling as follows:
gcc -o test test.c -Wall -std=c99 -lpthread -lm
Also, VS Code can't identify the function.
The problem is your -std=c99 option. Using strict C mode disables a bunch of stuff, including something that stops pthread_barrier_t from getting defined. If you use -std=gnu99 instead, it should compile. (Tested on Ubuntu 16.04 on WSL).
Alternatively, add
#define _XOPEN_SOURCE 600 /* Or higher */
or
#define _POSIX_C_SOURCE 200112L /* Or higher */
before the first #include in your source. See man 7 feature_test_macros for the acceptable values of these macros and more information.
I have a really simple c program that I want to compile using gcc, importing from linux kernel headers.
#include <stdio.h>
#include <stdlib.h>
#include <linux/random.h>
int main(){
int rand;
get_random_bytes(&rand,sizeof(rand));
printf("%d",rand);
return 0;
}
I have tried to compile this program using the following command:
gcc rand.c -D__KERNEL__ -isystem /lib/modules/`uname -r`/build/include
But I get a bunch of errors (below). What am I missing?:
/usr/src/kernels/4.9.8-201.fc25.x86_64/include/linux/linkage.h:7:25: fatal error: asm/linkage.h: No such file or directory
#include <asm/linkage.h>
From some quick Google searches, it seems like get_random_bytes might be a private function only usable from within the kernel.
How about you try using getrandom instead? Here is the documentation of getrandom:
http://man7.org/linux/man-pages/man2/getrandom.2.html
I have a program written in C which uses the following libraries:
#ifdef _WIN32
#include <winsock2.h>
#define socklen_t int
#else
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
In Windows, in order to compile this program with gcc, you had to use -lWs2_32 property.
How to compile it using gcc in linux?
-lWs2_32 is a linker option to specify a library to link. The compiler does not use it.
For gcc under Linux there is no need to explicitly specify a library when using socket functions.
I think you should statically link the executable and use MinGW. But it's just an assumption. Never tried it.
-lWs2_32 is a linker option to specify a library to link. The compiler does not use it.
For gcc under Linux there is no need to explicitly specify a library when using socket functions.
I am making these inclusions:
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
But still getting this warning.
You are probably passing the "-ansi -Wall" switches to the gcc compiler.
You can remove "-ansi" if you don't need it, otherwise try to set the proper feature define macro.
Something like:
#define _POSIX_SOURCE
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
You can also define it on the compile time by adding this flag with gcc.
-D_POSIX_C_SOURCE
ex:
-g -D_POSIX_C_SOURCE -Wall -std=c99
According to the kill(2) Linux manual page, _POSIX_C_SOURCE must be #defined before any includes in order for the prototype of the function kill() to be included through <signal.h> if you are using glibc.
Your code will probably compile either way, since the binary is available for linking regardless of the defines, but that's the proper way to silence this warning according to the documentation.