Error: file not recognized: File format not recognized c++ - c++

My Code:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
int main() {
cout << "hi my name is me" << endl;
return 0;
}
I used the command:
:!g++ %
to compile my code
When it compiled it returned:
testing.cpp~: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
shell returned 1
Furthermore, this is my current bits/stdc++.h header file:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
How do you fix this issue?

Assuming you're running this within vim, you're doing the right thing, as % gets replaced by the current file.
However, the fact that it's trying to compile testing.cpp~ (the vim backup for the testing.cpp file) indicates to me that you're editing the wrong file (or putting a ~ after the % on your command line).

Related

Precompiled headers don't make me compile faster

I've just coded this little project to try out pre-compiled headers with g++ :
main.cpp :
#include "header.hpp"
int main() {
std::cout << "Hello world !" << std::endl;
}
header.hpp :
#include <iostream>
#include <algorithm>
#include <functional>
#include <memory>
#include <thread>
#include <utility>
#include <string>
#include <stack>
#include <deque>
#include <array>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
First, I compile the project normally :
$ time g++ main.cpp
real 0m0.738s
user 0m0.646s
sys 0m0.070s
Then I delete the output and I type g++ header.hpp so I can get the precompiled header file : header.hpp.gch
I compile the project again :
$ time g++ main.cpp
real 0m0.721s
user 0m0.626s
sys 0m0.072s
The compile time is exactly the same ! What's the use of pre-compiled headers if they don't improve the compilation speed !?
Did I make a mistake or what ?

C++ use of undeclared identifier IOKit Functions

I am getting an error building my c++ program on xcode. For each of the various fuctions of the IOKit I am getting "use of undeclared identifier". I really don't know why I am getting this error. Here is the code:
#include <iostream>
#include <xlnt/xlnt.hpp>
#include <xlnt/xlnt_config.hpp>
#include <IOKitLib.h>
#include <IOTypes.h>
#include <IOReturn.h>
#include <IOKitKeys.h>
#include <iokitmig.h>
#include <OSMessageNotification.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <paths.h>
#include <termios.h>
#include <sysexits.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/serial/IOSerialKeys.h>
#include <IOKit/IOBSD.h>
#define LOCAL_ECHO
#ifdef LOCAL_ECHO
#define kOKResponseString “AT\r\r\nOK\r\n”
#else
#define kOKResponseString “\r\nOK\r\n”
#endif
#define kATCommandString "AT\r"
#define kMyErrReturn -1
enum {
kNumRetries = 3
};
static struct termios gOriginalTTYAttrs;
int main()
{
char path;
char text;
int fileDescriptor;
kern_return_t kernResult;
io_iterator_t serialPortIterator;
char deviceFilePath[MAXPATHLEN];
kernResult = MyFindModems(&serialPortIterator);
kernResult = MyGetModemPath(serialPortIterator, deviceFilePath,
sizeof(deviceFilePath));
Here is the image with all the errors shown: https://i.stack.imgur.com/e1UZS.jpg
Any advice would be more than appreciated. Is it because I haven't declared the functions?
Thanks in advance
Alex

OpenCV HOGDescriptor undefined

I wanted to use HOG but when I tried cv::HOGDescriptor hog; it gives me it is undefined? I included:
#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <vector>
#include <iterator>
#include <ctype.h>
#include <stdio.h>
#include <vector>
#include <iostream>
#include <math.h>
#include <numeric>
#include <cstdio>
#include <stdlib.h>
#include <iostream>
cv::HOGDescriptor is defined in "objdetect.hpp" .you have to include this header

g++ complaining about STD functions

I have a section of downloaded source code, when trying to compile via Cygwin using g++ compiler, the compiler gives me an error saying that the 'transform' function is undeclared in this scope...
I am using the std namespace, and I have the correct headers. I am not sure why it is not compiling.. The syntax looks correct
Here is the code block section.
string tolower (const string & s)
{
string d = s;
transform(d.begin(), d.end(), d.begin(), (int(*)(int)) tolower);
return d;
} // end of tolower
Here is my header section:
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
// standard library includes ...
#include <string>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stdexcept>
#include <fstream>
#include <iostream>
#include <sstream>
#include <ios>
#include <iterator>
using namespace std;
You need to include the appropriate header for std::transform:
#include <algorithm>
You should also avoid using namespace std; in the global namespace in headers, you pollute the global namespace of any code that includes your header file.
See this post about using namespace std.

Error: Expected constructor, destructor, type conversion before '<' token

the code is
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iterator>
#include <queue>
#include <algorithm>
#include <string>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <new>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
using std::vector;
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/operation.hpp>
#include <boost/numeric/ublas/vector.hpp>
using namespace boost::numeric::ublas;
boost::numeric::ublas::matrix<double> A_MATRIX(A_MATRIX_ROWS,A_MATRIX_COLUMNS);
boost::numeric::ublas::matrix<double> Y_MATRIX(A_MATRIX_ROWS,1);
vector <double> GPSR_BB(boost::numeric::ublas::matrix<double> &f_Y_MATRIX,boost::numeric::ublas::matrix<double> &f_A_MATRIX,int f_tau,int f_tolA){
vector<double> objective(2);
//sth inside function
return objective;
}
int main(){
vector<double> objectives(maxiter+2);
objectives=GPSR_BB(Y_MATRIX,A_MATRIX,tau,tolA);
return 0;
}
in line
vector <double> GPSR_BB(boost::numeric::ublas::matrix<double> &f_Y_MATRIX,boost::numeric::ublas::matrix<double> &f_A_MATRIX,int f_tau,int f_tolA){
I receive error
error: expected constructor, destructor, or type conversion before ‘<’ token function
I guess, the problem is because of matrix data type, from boost library, which I have to pass to function, I don't think there is another way I can do for my specific problem.
Any help is greatly appreciated. Thank you
boost::numeric::ublas has vector as well as namespace std. Try removing using namespace std and using the appropriate namespace to refer to the correct type.
Try without a space between vector and <double>
vector<double> GPSR_BB